title: How to add key-value pairs to hash in a loop
body: <p>I want to add key-value pairs to a hash in a loop. My hash looks like this</p>
  
  <pre><code>[ {'filename' =&gt; fileName1, 'filelocation'=&gt; fileLocation1}, {'filename' =&gt; fileName2, 'filelocation'=&gt; fileLocation2} ]
  </code></pre>
  
  <p>I am using the following code to do it. It does not add all values, but the very last key-value pair.</p>
  
  <pre><code>fileDetails= {}
  doc = REXML::Document.new args[0]
  doc.elements.each("node/congfigurations/config") {
   |config| 
      fileName= config.elements["@fileName"].value
      fileLocation= config.elements["@location"].value
      fileDetails={'filename' =&gt; fileName, 'filelocation'=&gt; fileLocation}
  }
  </code></pre>
  
  <p>How can I collect all values?</p>