mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Fix show-method in the face of overridden method method
This commit is contained in:
parent
ac26e57ad1
commit
40945bfbdf
2 changed files with 25 additions and 2 deletions
|
@ -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`
|
||||
|
|
|
@ -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/
|
||||
|
|
Loading…
Add table
Reference in a new issue