title: ruby - Inserting multiple hashes into an array in ruby
body: <p>I want to insert multiple hashes into an array which will create an array of hashes. But every time I add a new hash to the array, it would overwrite the previous ones. Any idea what is going on?</p>
  
  <pre><code>partArray = [] 
  partHash = {}
  
  partHash["name"] = "Item1"
  partHash["owner"] = "Item1"
  
  #Insert first hash into array
  partArray &lt;&lt; partHash
  puts partArray 
  
  #new set of key, value pairs
  #to be appended to array 
  partHash["name"] = "Item2"
  partHash["owner"] = "Item2"
  
  #Append second hash into array
  partArray &lt;&lt; partHash
  
  puts partArray
  </code></pre>
  
  <p>output : </p>
  
  <pre><code>{"name"=&gt;"Item1", "owner"=&gt;"Item1"}
  new Array is : 
  {"name"=&gt;"Item2", "owner"=&gt;"Item2"}
  {"name"=&gt;"Item2", "owner"=&gt;"Item2"}
  </code></pre>
  
  <p>I'm not sure why the values in the first hash were overwritten. Any help is appreciated.</p>