From: Massimiliano Mirra Date: 2001-11-17T09:03:39+09:00 Subject: [ruby-talk:25687] Re: Getting a class object from a string containg its name On Sat, Nov 17, 2001 at 01:09:55AM +0900, Lars Christensen wrote: > I need to get a reference to a class object from a string with the > name of the class. I want to do this in a secure way because the > string comes from an external source. I could not find any easy way > to convert a string or symbol to a class reference. I found two > approaches though: There was a discussion about this a while ago. available_classes = Hash.new [Array, String, Fixnum].each do |klass| available_classes[klass.to_s] = klass end When you want to refer to them write something like: s = "Array" ary = available_classes[s].new This way you control and restrict which and how many classes you can refer to through their names. I'm not totally sure that this was what resulted from the discussion, you might want to check the archives. Massimiliano