From: Anders Borch Date: 2003-07-01T05:23:35+09:00 Subject: Re: dynamic object creation Brian Candler wrote: > On Tue, Jul 01, 2003 at 01:01:25AM +0900, Aryeh Friedman wrote: > >>If I have something like this: >> >>s="Array" >> >>How whould I get something like this: >> >>aObject=s.new >> >>In "plain" english I am asking if I have a valid name of a class in a >>string how do I create an instance of the class the string contains? > > > A class name is just a constant, so something like > > a = Module.const_get("Array").new uhm... why does this work? I just tested it and to my surprise it worked?! http://rubycentral.com/book/ref_c_module.html#Module.const_get says that I need to supply a symbol, why does it accept a string? is this something that will continue to work in 1.8? (im still using 1.6.8 on my winbox and 1.6.7 on my linux box) > > is what you need (Aside: what's the proper way to access 'the top-level > Module', or is the above correct?) > > Cheers, > > Brian. > -- dc -e 4dd*od3*dddn1-89danrn10-dan3+ann6*dan*2*an13dn1+dn2-dn3+5*ddan2/9+an13nap