From: Matthew Thill Date: 2005-04-30T03:16:12+09:00 Subject: Re: Creating arbitrary objects Yes, that is exactly what I wanted. Thank you. James Edward Gray II wrote: > On Apr 29, 2005, at 12:38 PM, Matthew Thill wrote: > >> I've probably overlooked something, and hopefully someone can help me >> out. I want to be able to create arbitrary object from the contents of >> a string. >> >> For example, if I had the following string: >> >> classname = "Array" >> >> How can I create an Array object, knowing only that the variable >> classname held the name of some class as a string. > > > You're looking for Object.const_get(): > > irb(main):003:0> class_obj = Object.const_get("Array") > => Array > irb(main):004:0> arr = class_obj.new > => [] > > Hope that helps. > > James Edward Gray II > >