Convert string to instance variable

Is there anyway to convert a string to an instance varible?

eg.
Suppose I have @name defined.
Is there any method that would return @name given the string “name” ?

Also, is there a similar method for local variables?

Thanks in advance,
Thushan

Hi,

Thushan a écrit :

Is there anyway to convert a string to an instance varible?

Yes there is. Just try instance_variable_get(“@name”) and you’ll have
the value of @name.

You should read the documentation of the Object class for more
information :slight_smile:
http://www.ruby-doc.org/core/classes/Object.html

Cheers,

Thanks Loïc.
instance_variable_get and instance_variable_set worked for me.

What about local variables?

/ Thushan