diff --git a/lib/pry/method.rb b/lib/pry/method.rb index 4b23005d..da46f81b 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -47,6 +47,9 @@ class Pry elsif name.to_s =~ /(.+)\#(\S+)\Z/ context, meth_name = $1, $2 from_module(target.eval(context), meth_name, target) + elsif name.to_s =~ /(.+)(\[\])\Z/ + context, meth_name = $1, $2 + from_obj(target.eval(context), meth_name, target) elsif name.to_s =~ /(.+)(\.|::)(\S+)\Z/ context, meth_name = $1, $3 from_obj(target.eval(context), meth_name, target) diff --git a/spec/method_spec.rb b/spec/method_spec.rb index 86a32516..304c6feb 100644 --- a/spec/method_spec.rb +++ b/spec/method_spec.rb @@ -68,6 +68,18 @@ describe Pry::Method do meth.name.should == "hello" end + it 'should take care of corner cases like mongo[] e.g Foo::Bar.new[]- issue 998' do + klass = Class.new { def []; :hello; end } + meth = Pry::Method.from_str("klass.new[]", Pry.binding_for(binding)) + meth.name.should == "[]" + end + + it 'should take care of cases like $ mongo[] - issue 998' do + f = Class.new { def []; :hello; end }.new + meth = Pry::Method.from_str("f[]", Pry.binding_for(binding)) + meth.name.should == "[]" + end + it 'should look up instance methods using klass.meth#method syntax' do klass = Class.new { def self.meth; Class.new; end } meth = Pry::Method.from_str("klass.meth#initialize", Pry.binding_for(binding))