diff --git a/lib/pry/core_extensions.rb b/lib/pry/core_extensions.rb index d156eb4e..be311965 100644 --- a/lib/pry/core_extensions.rb +++ b/lib/pry/core_extensions.rb @@ -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`). diff --git a/spec/commands/cd_spec.rb b/spec/commands/cd_spec.rb index f4863f34..0b17358b 100644 --- a/spec/commands/cd_spec.rb +++ b/spec/commands/cd_spec.rb @@ -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