I have a local variable name as a string, and need to get its value.
variable = 22
"variable".to_variable?
How can I get the value 22
form the string?
I have a local variable name as a string, and need to get its value.
variable = 22
"variable".to_variable?
How can I get the value 22
form the string?
You can use
eval
.However
eval
can be nasty. If you dont mind declaring an instance variable, you can do something like this too: