From: Joel VanderWerf Date: 2004-07-30T02:33:30+09:00 Subject: Re: code introspection Robert Klemme wrote: > "gabriele renzi" schrieb im Newsbeitrag > news:rkjcg0tf6o9g63lnb6lo9gk5bsjvg82kcd@4ax.com... ... >> load(filename, wrap=false) => true >>----------------------------------------------------------------------- >> Loads and executes the Ruby program in the file _filename_. If the >> filename does not resolve to an absolute path, the file is >>searched >> for in the library directories listed in +$:+. If the optional >> _wrap_ parameter is +true+, the loaded script will be executed >> under an anonymous module, protecting the calling program's global >> namespace. In no circumstance will any local variables in the >> loaded file be propagated to the loading environment. > > > Yes, but that doesn't help here since there's no way to find this > anonymous module in order to find all classes defined in the file. I > tried that initially, too, but the return value of load is not the module > but 'true' or 'false'. Or am I missing somethig? The anonymous module is not even reachable, so it will get GC-ed, as in this example: irb(main):002:0> def foo; load "f.rb", true; end => nil irb(main):003:0> ObjectSpace.each_object(Module){} => 372 irb(main):004:0> foo => true irb(main):005:0> ObjectSpace.each_object(Module){} => 373 irb(main):006:0> foo => true irb(main):007:0> ObjectSpace.each_object(Module){} => 374 irb(main):008:0> GC.start => nil irb(main):009:0> ObjectSpace.each_object(Module){} => 372 Getting one's hands on the wrapper module is the raison d'etre of my little "script" lib (http://redshift.sourceforge.net/script). More simply, you can just read the file and use module_eval (but script adds some features).