Fix show-method in the face of overridden method method

This commit is contained in:
Conrad Irwin 2012-02-28 06:37:44 -08:00
parent ac26e57ad1
commit 40945bfbdf
2 changed files with 25 additions and 2 deletions

View File

@ -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`

View File

@ -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/