il 26 Jul 2004 03:19:36 -0700, daniel / danielcremer.com (Daniel Cremer)
ha scritto::

>I would like to load ruby source files and dynamically create objects
>from classes located inside these sources. It's one class/object per
>source file and I can  make it so that a string from a configuration
>file holds the name of the class. However I can't figure out a good
>way to use that string to get to the class in the source file.

something like:

'Myclass' in 'Myclass.rb' or the file names are not related

>I could use eval but am really uncomfortable with that for obvious
>reasons (people keep saying it's evil so I don't play with him). The
>other solution I came up with was to add a method in the same source
>but outside the class to return the desired object:


you may use const_get:
>> class Foo
>> end
=> nil
>> Object::const_get('Foo').new
=> #<Foo:0x28b3eb8>