title: Using the value of a variable as another variables name in Ruby
body: <p>I'm just starting out in learning Ruby and I've written a program that generates some numbers and assigns them to variables @one, @two, @three etc. The user can then specify a variable to change by inputting it's name (e.g one). I then need to do something like '@[valueofinout] = asd'. How would I do this, and is there a better way as the way I'm thinking of seems to be discouraged? I've found</p>
  
  <pre><code>x = "myvar"
  myvar = "hi"
  eval(x) -&gt; "hi"
  </code></pre>
  
  <p>but I don't completely understand why the second line is needed. In my case would I use something like</p>
  
  <pre><code>@one = "21"
  input = "one"
  input = "@" + input
  changeto = "22"
  eval(input) -&gt; changeto
  </code></pre>