From f1f54d2ecb96d8f72678464f0cc6923760887997 Mon Sep 17 00:00:00 2001 From: John Mair Date: Wed, 19 Dec 2012 12:01:45 +0100 Subject: [PATCH] Allow Pry::WrappedModule.from_str() to look up modules from locals/ivars No longer restricted to just constants. --- lib/pry/wrapped_module.rb | 2 +- spec/wrapped_module_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb index 4791d63c..b1fab206 100644 --- a/lib/pry/wrapped_module.rb +++ b/lib/pry/wrapped_module.rb @@ -31,7 +31,7 @@ class Pry # if we dont limit it to constants then from_str could end up # executing methods which is not good, i.e `show-source pry` - if (kind == "constant" && target.eval(mod_name).is_a?(Module)) + if ((kind == "constant" || kind =~ /variable/) && target.eval(mod_name).is_a?(Module)) Pry::WrappedModule.new(target.eval(mod_name)) else nil diff --git a/spec/wrapped_module_spec.rb b/spec/wrapped_module_spec.rb index db62ca40..3468cdbc 100644 --- a/spec/wrapped_module_spec.rb +++ b/spec/wrapped_module_spec.rb @@ -223,4 +223,23 @@ describe Pry::WrappedModule do end end end + + describe ".from_str" do + it 'should lookup a constant' do + m = Pry::WrappedModule.from_str("Host::CandidateTest", binding) + m.wrapped.should == Host::CandidateTest + end + + it 'should lookup a local' do + local = Host::CandidateTest + m = Pry::WrappedModule.from_str("local", binding) + m.wrapped.should == Host::CandidateTest + end + + it 'should lookup an ivar' do + @ivar = Host::CandidateTest + m = Pry::WrappedModule.from_str("@ivar", binding) + m.wrapped.should == Host::CandidateTest + end + end end