On 4/10/06, Brian Parkinson <parkI / whatevernot.com> 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=> #<K:0xb7fc1788>irb(main):004:0> k2 = eval('K').new=> #<K:0xb7fb8094>irb(main):005:0> k3 = Object.const_get('K').new=> #<K:0xb7fb1474>
--http://nohmad.sub-port.net