Allow Pry::WrappedModule.from_str() to look up modules from locals/ivars

No longer restricted to just constants.
This commit is contained in:
John Mair 2012-12-19 12:01:45 +01:00
parent c7b28efc24
commit f1f54d2ecb
2 changed files with 20 additions and 1 deletions

View File

@ -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

View File

@ -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