diff --git a/lib/pry/method.rb b/lib/pry/method.rb index 078401c6..1162e712 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -109,7 +109,7 @@ class Pry # @param [String] name # @return [Pry::Method, nil] def from_class(klass, name) - new(klass.instance_method(name)) rescue nil + new(safe_send(klass, :instance_method, name)) rescue nil end alias from_module from_class @@ -121,7 +121,7 @@ class Pry # @param [String] name # @return [Pry::Method, nil] def from_obj(obj, name) - new(obj.method(name)) rescue nil + new(safe_send(obj, :method, name)) rescue nil end # Get all of the instance methods of a `Class` or `Module` diff --git a/test/test_default_commands/test_introspection.rb b/test/test_default_commands/test_introspection.rb index 4bd00a41..1684ffdc 100644 --- a/test/test_default_commands/test_introspection.rb +++ b/test/test_default_commands/test_introspection.rb @@ -320,6 +320,29 @@ describe "Pry::DefaultCommands::Introspection" do str_output.string.should =~ /Mr flibble/ end + it "should find methods even if the object has an overridden method method" do + c = Class.new{ + def method; + 98 + end + } + + mock_pry(binding, "show-method c.new.method").should =~ /98/ + end + + it "should find instance_methods even if the class has an override instance_method method" do + c = Class.new{ + def method; + 98 + end + + def self.instance_method; 789; end + } + + mock_pry(binding, "show-method c#method").should =~ /98/ + + end + it "should find instance methods with -M" do c = Class.new{ def moo; "ve over!"; end } mock_pry(binding, "cd c","show-method -M moo").should =~ /ve over/