Is there any way to access objects (eg. constants) from within a
‘module’
that was loaded with wrap=true, like
foo.rb:
X = 1
baz.rb:
load(‘foo.rb’,true)
puts X
?
I don’t think, you can access them from the outside, because the purpose
of wrap=true is exactly to hide them:
“Any local variables in the loaded file will not be propagated to the
loading environment.”
If you want to expose them you’ll better put them into a module and load
with wrap = false. After all, why do you hide them if you want to expose
them?
Is there any way to access objects (eg. constants) from within a ‘module’
that was loaded with wrap=true, like
foo.rb:
X = 1
baz.rb:
load(‘foo.rb’,true)
puts X
AFAIK, only through nefarious programming:
def collect_modules
mods =
ObjectSpace.each_object(Module){|m| mods << m }
mods
end
before = collect_modules
load(‘foo.rb’,true)
after = collect_modules
m = (after - before)[0]
puts m::X
Very thread unsafe btw. There probably exists some neat hooks, but I
can’t find any right now.
···
–
([ Kent Dahl ]/)_ ~[ http://www.pvv.org/~kentda/ ]/~
))_student_/(( _d L b_/ (pre-) Master of Science in Technology )
( __õ|õ// ) )Industrial economics and technological management(
_/ö____/ (_engineering.discipline=Computer::Technology)