From: pjb@... (Pascal J. Bourguignon) Date: 2009-01-24T10:43:09+09:00 Subject: Re: instantiate a class dynamically "rpardee@gmail.com" writes: > Hey All, > > If I have the name of a class in a string var, is it possible to get a > new instance of that class (and if so, how)? The following do *not* > work: > > my_string = "Hash" > > my_object = Class(my_string) > my_object = Class.new(my_string) > my_object = Object.new(my_string) Class names are used to define constants in the Module module: irb(main):014:0> className="Hash" "Hash" irb(main):015:0> Module.constants.member?(className) true Therefore you should be able to get the class with: irb(main):016:0> Module.class_eval(className) Hash and make an instance with: irb(main):017:0> Module.class_eval(className).new {} -- __Pascal Bourguignon__