summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Anderson <panic@semiosix.com>2017-07-31 08:26:25 +0200
committer0xAB <0xAB@protonmail.com>2017-08-20 15:03:26 +0100
commite98e852bc16d728d4f1207e8ce0ba0103a167877 (patch)
treec9b7d263e27f8590d33a124bbda3f1788c737057
parentdc98d2f35b3745b13b0eac22e67bc6e096b940df (diff)
downloadpry-e98e852bc16d728d4f1207e8ce0ba0103a167877.tar.gz
Pry::WrappedModule::Candidate#class_regexes now handles modules that have overidden Module.name
-rw-r--r--lib/pry/wrapped_module/candidate.rb10
-rw-r--r--spec/wrapped_module_spec.rb11
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/pry/wrapped_module/candidate.rb b/lib/pry/wrapped_module/candidate.rb
index 67ef1925..3481b2d0 100644
--- a/lib/pry/wrapped_module/candidate.rb
+++ b/lib/pry/wrapped_module/candidate.rb
@@ -97,9 +97,13 @@ class Pry
def class_regexes
mod_type_string = wrapped.class.to_s.downcase
- [/^\s*#{mod_type_string}\s+(?:(?:\w*)::)*?#{wrapped.name.split(/::/).last}/,
- /^\s*(::)?#{wrapped.name.split(/::/).last}\s*?=\s*?#{wrapped.class}/,
- /^\s*(::)?#{wrapped.name.split(/::/).last}\.(class|instance)_eval/]
+
+ # workaround for things that redefine Module.name - yes, they're out there.
+ wrapped_name = Pry::Helpers::BaseHelpers.safe_send wrapped, :name
+
+ [/^\s*#{mod_type_string}\s+(?:(?:\w*)::)*?#{wrapped_name.split(/::/).last}/,
+ /^\s*(::)?#{wrapped_name.split(/::/).last}\s*?=\s*?#{wrapped.class}/,
+ /^\s*(::)?#{wrapped_name.split(/::/).last}\.(class|instance)_eval/]
end
# This method is used by `Candidate#source_location` as a
diff --git a/spec/wrapped_module_spec.rb b/spec/wrapped_module_spec.rb
index b46d9cac..ae4658b9 100644
--- a/spec/wrapped_module_spec.rb
+++ b/spec/wrapped_module_spec.rb
@@ -35,6 +35,17 @@ describe Pry::WrappedModule do
end
end
end
+
+ module ModuleNameOverride
+ def self.name; 'Not a good idea, but it happens in the wild.' end
+ end
+ end
+
+ describe 'overidden Module#name' do
+ it 'should resolve correct name' do
+ wm = Pry::WrappedModule(Host::ModuleNameOverride)
+ expect(wm.candidate(0).source_location).not_to be_nil
+ end
end
describe "number_of_candidates" do