From: Robert Klemme Date: 2004-07-29T18:36:52+09:00 Subject: Re: code introspection "gabriele renzi" schrieb im Newsbeitrag news:rkjcg0tf6o9g63lnb6lo9gk5bsjvg82kcd@4ax.com... > il Mon, 26 Jul 2004 23:56:40 +0900, Daniel Cremer > ha scritto:: > > >> If you don't know class names beforehand, you can work with an anonymous > >> module as wrapper like this: > >> > >> mod = Module.new > >> mod.class_eval( File.read( "foo.rb" ) ) > >> new_classes = mod.constants.inject([]) {|ar,c| cl=mod.const_get(c); ar << > >> cl if Class === cl; ar} > >> p new_classes > >> include mod > >> p Foo > >> > >> (...) > > > >ahh... it looks like creating an anonymous module is the piece that is > >really missing for me at the moment... > >thanks for the ideas, I'm not sure how far I'll have to carry this so > >they're all appreciated > > > > well, than take a look at the simple load: > > 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? Regards robert