Allow Pry::WrappedModule.from_str() to look up modules from locals/ivars
No longer restricted to just constants.
This commit is contained in:
parent
c7b28efc24
commit
f1f54d2ecb
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue