On Mon, 2004-07-26 at 14:16, Robert Klemme wrote:
> "Lothar Scholz" <mailinglists / scriptolutions.com> schrieb im Newsbeitrag
> news:178359988968.20040726131022 / scriptolutions.com...
> > Hello Daniel,
> >
> > DC> Is there a solution to do code introspection rather than
> introspection
> > DC> at the level of the Module/Object ? I can't figure out if I'm
> looking
> >
> > Yes but only from the C level. You need to create the "Node" tree and
> > travere it. Unfortuneatly there seems to be no visitor pattern class to
> do
> > this and you must expect that the Node structure can change even
> > between minor updates a lot. So read the code in eval.c and parse.c.
> 
> Err, I think this is overkill.  Daniel just wants to create an instance of
> a class whose name he knows.  So the already suggested Object.const_get(
> class_name ) or ObjectSpace.const_get( class_name ) suffices.
> 
> 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

	-Daniel