creating instance of an object without knowing it's name

Hi, I have a variable @foo that holds the name of an object. How I can create a instance of that object.

An example:

I need to create a instance of an "Elephant" object

@object_name = "Elephant" @object_name.new # this does'nt work

Is there a way to do this without eval ?

Regards

Hi, I have a variable @foo that holds the name of an object. How I can create a instance of that object.

An example:

I need to create a instance of an "Elephant" object

@object_name = "Elephant" @object_name.new # this does'nt work

Is there a way to do this without eval ?

constantize

http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html#M001058

Fred