From e2f9e1e6e8ae028fa2fbb66d6dd3015cfcae1ff8 Mon Sep 17 00:00:00 2001 From: Deepender Date: Mon, 9 Dec 2013 06:52:34 +0530 Subject: [PATCH 1/8] solved issue 998 --- lib/pry/method.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/pry/method.rb b/lib/pry/method.rb index 4b23005d..cceff36a 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -50,6 +50,9 @@ class Pry elsif name.to_s =~ /(.+)(\.|::)(\S+)\Z/ context, meth_name = $1, $3 from_obj(target.eval(context), meth_name, target) + elsif name.to_s =~ /(\w+)(\[\])/ + context, meth_name = $1, $2 + from_obj(target.eval(context), meth_name, target) elsif options[:instance] from_module(target.eval("self"), name, target) elsif options[:methods] From f1e07ce255d6c7c2aad5bb0505443c4e4016a378 Mon Sep 17 00:00:00 2001 From: Deepender Date: Tue, 10 Dec 2013 00:50:29 +0530 Subject: [PATCH 2/8] issue 998 --- Gemfile | 1 + lib/pry/method.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 11553a13..53000492 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ group :development do gem 'jist' gem 'rb-inotify', :require => 'false' gem 'rb-fsevent', :require => 'false' + gem 'debugger' end if RbConfig::CONFIG['ruby_install_name'] == 'rbx' diff --git a/lib/pry/method.rb b/lib/pry/method.rb index cceff36a..455f0c9b 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -50,7 +50,7 @@ class Pry elsif name.to_s =~ /(.+)(\.|::)(\S+)\Z/ context, meth_name = $1, $3 from_obj(target.eval(context), meth_name, target) - elsif name.to_s =~ /(\w+)(\[\])/ + elsif name.to_s =~ /(.+)(\[\])\Z/ context, meth_name = $1, $2 from_obj(target.eval(context), meth_name, target) elsif options[:instance] From c8480d7a0f76a45fea19ae2057f84f3ff5410f24 Mon Sep 17 00:00:00 2001 From: Deepender Date: Tue, 10 Dec 2013 07:36:45 +0530 Subject: [PATCH 3/8] issue 998 --- lib/pry/method.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/pry/method.rb b/lib/pry/method.rb index 455f0c9b..50ab1d92 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -48,8 +48,13 @@ class Pry context, meth_name = $1, $2 from_module(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) + if($3 == "new[]") + name.to_s =~ /(.+)(\[\])\Z/ + context, meth_name = $1, $2 + else + context, meth_name = $1, $3 + end + from_obj(target.eval(context), meth_name, target) elsif name.to_s =~ /(.+)(\[\])\Z/ context, meth_name = $1, $2 from_obj(target.eval(context), meth_name, target) From 8ce2397bb47303e00a7bad2d5a7eccf4648d1a02 Mon Sep 17 00:00:00 2001 From: Deepender Date: Tue, 10 Dec 2013 07:41:26 +0530 Subject: [PATCH 4/8] issue 998 --- lib/pry/method.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pry/method.rb b/lib/pry/method.rb index 50ab1d92..acb74469 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -54,7 +54,7 @@ class Pry else context, meth_name = $1, $3 end - from_obj(target.eval(context), meth_name, target) + from_obj(target.eval(context), meth_name, target) elsif name.to_s =~ /(.+)(\[\])\Z/ context, meth_name = $1, $2 from_obj(target.eval(context), meth_name, target) From 24ab88a307ba74b6b82d33995519a08fe50b3821 Mon Sep 17 00:00:00 2001 From: Deepender Date: Wed, 11 Dec 2013 15:43:05 +0530 Subject: [PATCH 5/8] issue 998 test added --- Gemfile | 1 - lib/pry/method.rb | 2 +- spec/method_spec.rb | 15 ++++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 53000492..11553a13 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,6 @@ group :development do gem 'jist' gem 'rb-inotify', :require => 'false' gem 'rb-fsevent', :require => 'false' - gem 'debugger' end if RbConfig::CONFIG['ruby_install_name'] == 'rbx' diff --git a/lib/pry/method.rb b/lib/pry/method.rb index acb74469..f413a70d 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -64,7 +64,7 @@ class Pry from_obj(target.eval("self"), name, target) else from_str(name, target, :instance => true) or - from_str(name, target, :methods => true) + from_str(name, target, :methods => true) end rescue Pry::RescuableException diff --git a/spec/method_spec.rb b/spec/method_spec.rb index 86a32516..4ab97060 100644 --- a/spec/method_spec.rb +++ b/spec/method_spec.rb @@ -62,12 +62,25 @@ describe Pry::Method do meth.should == nil end - it 'should look up methods using klass.new.method syntax' do + it 'should look up methods using klass.new.method syntax' do klass = Class.new { def hello; :hello; end } meth = Pry::Method.from_str("klass.new.hello", Pry.binding_for(binding)) 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 } + binding.eval("f = {}") + 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)) From 5717ff487ba4e23ab2220accc66cae7ee1e67833 Mon Sep 17 00:00:00 2001 From: Deepender Date: Wed, 11 Dec 2013 16:39:52 +0530 Subject: [PATCH 6/8] method_spec.rb fixed --- spec/method_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/method_spec.rb b/spec/method_spec.rb index 4ab97060..1ec022e5 100644 --- a/spec/method_spec.rb +++ b/spec/method_spec.rb @@ -75,8 +75,7 @@ describe Pry::Method do end it 'should take care of cases like $ mongo[] - issue 998' do - f = Class.new { def []; :hello; end } - binding.eval("f = {}") + f = Class.new { def []; :hello; end }.new meth = Pry::Method.from_str("f[]", Pry.binding_for(binding)) meth.name.should == "[]" end From 4cf1d050348f7df14a22c96869bf90c18d58e502 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 11 Dec 2013 08:44:22 -0800 Subject: [PATCH 7/8] Simplify By putting the check for [] first, we don't need to handle the case where that's part of the method. --- lib/pry/method.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/pry/method.rb b/lib/pry/method.rb index f413a70d..053d7614 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -47,17 +47,12 @@ 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 =~ /(.+)(\.|::)(\S+)\Z/ - if($3 == "new[]") - name.to_s =~ /(.+)(\[\])\Z/ - context, meth_name = $1, $2 - else - context, meth_name = $1, $3 - end - from_obj(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) elsif options[:instance] from_module(target.eval("self"), name, target) elsif options[:methods] From 01c6f60b7a181de9cb603c76a2567b6e975baafc Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 11 Dec 2013 08:44:49 -0800 Subject: [PATCH 8/8] undo whitespace changes --- lib/pry/method.rb | 2 +- spec/method_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pry/method.rb b/lib/pry/method.rb index 053d7614..da46f81b 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -59,7 +59,7 @@ class Pry from_obj(target.eval("self"), name, target) else from_str(name, target, :instance => true) or - from_str(name, target, :methods => true) + from_str(name, target, :methods => true) end rescue Pry::RescuableException diff --git a/spec/method_spec.rb b/spec/method_spec.rb index 1ec022e5..304c6feb 100644 --- a/spec/method_spec.rb +++ b/spec/method_spec.rb @@ -62,7 +62,7 @@ describe Pry::Method do meth.should == nil end - it 'should look up methods using klass.new.method syntax' do + it 'should look up methods using klass.new.method syntax' do klass = Class.new { def hello; :hello; end } meth = Pry::Method.from_str("klass.new.hello", Pry.binding_for(binding)) meth.name.should == "hello"