mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
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
2 changed files with 20 additions and 1 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue