0

I would like to know if it is possible to convert a string in ruby to a variable. For example if I want the user to input a string with .get and then want to set the string they put to the name of a variable.

How can I make this work for example:

name=gets.chomp
name_var=#name as variable
name_var=Class.new

Thank you.

Pabi
  • 946
  • 3
  • 16
  • 47
  • 2
    I believe your question has already been asked: [Using a string as a variable at run time ][1] [1]: http://stackoverflow.com/questions/881239/using-a-string-as-a-variable-at-run-time – EdgarAllenPoe Jul 12 '15 at 02:28
  • 1
    This sounds like a XY problem to me. Probably a hash might be a much better solution. Can you please explain why you want to do that. – spickermann Jul 12 '15 at 03:35

0 Answers0