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.

2
  • 2
    I believe your question has already been asked: [Using a string as a variable at run time ][1] [1]: stackoverflow.com/questions/881239/… Commented Jul 12, 2015 at 2: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. Commented Jul 12, 2015 at 3:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.