Merge pull request #1811 from pry/redefined-respond-to-fix

core_extensions: make '__binding__' work with redefined #respond_to?
This commit is contained in:
Kyrylo Silin 2018-10-17 23:18:39 +08:00 committed by GitHub
commit d9650b2cdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -87,7 +87,7 @@ class Object
return class_eval("binding")
end
unless respond_to?(:__pry__)
unless self.class.method_defined?(:__pry__)
# The easiest way to check whether an object has a working singleton class
# is to try and define a method on it. (just checking for the presence of
# the singleton class gives false positives for `true` and `false`).

View File

@ -250,4 +250,10 @@ describe 'cd' do
it 'should be able to cd into the Object BasicObject' do
expect { @t.eval 'cd BasicObject.new' }.to_not raise_error
end
# https://github.com/pry/pry/issues/1596
it "can cd into objects that redefine #respond_to? to return true" do
expect { @t.eval('cd Class.new { def respond_to?(m) true end }.new') }
.to_not raise_error
end
end