From: Gyoung-Yoon Noh Date: 2006-04-10T03:26:50+09:00 Subject: Re: Dumb reflection problem - create object from String On 4/10/06, Brian Parkinson wrote:> Hello - I'm bashing my head against the wall - I'm sure this is a simple> question, but damned if I can figure it out.>> If I have a String which corresponds to a class name, how do I create an> instance of this class?>> Example:>> class MyExampleClass> ...> end>> s = 'MyExampleClass'>> # We want to instantiate a new instance of the class> myExampleClassInstance = ???>> I want the behaviour of 'MyExampleClass.new' but only using the String> value of s.>> I'm sure it's a one-liner.>> Any help appreciated.>> Thanks.>> parki...>>> --> Posted via http://www.ruby-forum.com/.>> $ irbirb(main):001:0> class Kirb(main):002:1> end=> nilirb(main):003:0> k1 = K.new=> #irb(main):004:0> k2 = eval('K').new=> #irb(main):005:0> k3 = Object.const_get('K').new=> # --http://nohmad.sub-port.net