From: Brian Candler Date: 2009-05-26T02:26:45+09:00 Subject: Re: dynamic object creation Ken Tyler wrote: > sorry if i've missed something obvious > > is there a way in ruby to dynamically create an object from a variable > that holds the object's name? That doesn't make sense - if the object has a name then surely it already exists? Perhaps you wish to create an object where a variable holds the name of the *class* you wish to create a new instance of. In that case: klassname = "String" klass = Object.const_get(klassname) foo = klass.new If the class name contains :: scope separator, then you need to split on that first. klass = klassname.split('::').inject(Object) { |base,item| base.const_get(item) } -- Posted via http://www.ruby-forum.com/.