From: pjb@... (Pascal J. Bourguignon) Date: 2009-03-29T23:40:05+09:00 Subject: Re: Dynamic object creation in ruby Robert Klemme writes: > On 29.03.2009 13:40, Brian Candler wrote: >>> frank = Object.const_get("Master::Person").new("Frank") >>> >>> Does anyone know why the second way fails? >> frank = Master.const_get("Person").new("Frank") > > Erm, that's a hybrid solution. If you know the names beforehand, you > can just do > > frank = Master::Person.new "Frank" Then the answer for the OP would be: frank = Object.const_get("Master").const_get("Person").new("Frank") const_get takes only a simple constant name, not a qualified name. irb(main):247:0> (module Master (class Person (def initialize(name) @name=name end) end) end) nil irb(main):254:0> frank = Object.const_get("Master").const_get("Person").new("Frank") # > I would assume that the OP receives the full qualified name as a > String and wants to get the class from there which can only be > achieved with any of the other solutions shown. Obviously, he wants to replace the literals by variables. -- __Pascal Bourguignon__