title: Creating an array of hashes from user input in Ruby
body: <p>I am trying to create a simple bank account program to practice some Ruby.  The idea is to create an array of hashes.  However, I want to use user input to create a new hash, whether that be creating the title or simply numbering the entries something like user1 or user2.</p>
  
  <p>If I use a set up that stores the username, pin, and balance all inside the hash, like so:</p>
  
  <pre><code>jhip = {
    :pin =&gt; 1234,
    :balance =&gt; 1000000
  }
  
  jdog = {
    :pin =&gt; 2345,
    :balance =&gt; 1000
  }
  
  accounts = [
    jhip,
    jdog
  ]
  </code></pre>
  
  <p>I feel it will be much easier to find the right username in the array and/or tell the user that their name has already been chosen than if I used a set up like this:</p>
  
  <pre><code>user1 = {
    :username =&gt; "jhip",
    :pin =&gt; 1234,
    :balance =&gt; 1000000
  }
  
  user2 = {
    :username =&gt; "jdog",
    :pin =&gt; 2345,
    :balance =&gt; 1000
  }
  
  accounts = [
    user1,
    user2
  ]
  </code></pre>
  
  <p>The real meat of this problem is getting the user input to be the title of the hash.  I know the notation for creating a hash like this:</p>
  
  <pre><code>h = hash.new #or
  hash = {}
  </code></pre>
  
  <p>But I don't know how to use the input as a title.  When I store the input as a variable, I can play with the variable:</p>
  
  <pre><code>@username = gets.chomp
  @username.to_i #or any method
  </code></pre>
  
  <p>But if I try to create a hash with the variable name, I overwrite the input.</p>
  
  <pre><code>@username = {} #no more using the response from gets
  </code></pre>
  
  <p>I guess what I'm looking for would be something like</p>
  
  <pre><code>@username = gets.chomp
  @username.to_s =&gt; (some sort of code or command I'm unaware of) {}
  </code></pre>
  
  <p>And then I can push the key and value pairs into the hash.  I don't know if I could use a block to accomplish this or something else.  I'm still new to this, so I apologize if I bit off more than I can chew with this problem.  Thanks for any help.</p>