title: How can I access hashes within an array?
body: <p>I'm trying to use Nokogiri to grab some data from an XML file, then save it into the database.</p>
  
  <p>The code I'm using is:</p>
  
  <pre><code>def self.import_from_feed(feed)
   doc = Nokogiri::XML(open(feed))
  
   @products = doc.xpath('/merchantProductFeed/merchant/prod').map do |i| 
     {
       'name' =&gt; i.xpath('text/name').inner_text,
       'link' =&gt; i.xpath('uri/mLink').inner_text, 
       'description' =&gt; i.xpath('text/desc').inner_text,
       'price' =&gt; i.xpath('price/buynow').inner_text
     }
   end
  end
  </code></pre>
  
  <p>In Rails' console, I ran <code>Products.import_from_feed(myfeedgoeshere)</code> and got:</p>
  
  <pre><code>[{"price"=&gt;"8.00", "name"=&gt;"BASIC GIRL BOXER", "description"=&gt;"Boxer shorts Elasticated waist with Bench logo Button fly", "link"=&gt;"http://www.bench.co.uk/womenswear/underwear/basic-girl-boxer/GY001X/"}, {"price"=&gt;"10.00", "name"=&gt;"CMTL  PK SPORTY SOCKS", "description"=&gt;"Ankle sockBench logo on sole of each sockContrasting stripe around ankle", "link"=&gt;"http://www.bench.co.uk/womenswear/underwear/cmtl03593-3-pk-sporty-socks/BK014-SK034/"}, {"price"=&gt;"12.00", "name"=&gt;"A PK STRING UNDERWEAR", "description"=&gt;"Plain thong Bench logo along waistband Bench tag on front", "link"=&gt;"http://www.bench.co.uk/womenswear/underwear/a4771-3pk-string-underwear/PK023-BK001-WH001/"}, {"price"=&gt;"8.00", "name"=&gt;"BASIC GIRL BOXER", "description"=&gt;"Boxer shorts Elasticated waist with Bench logo Button fly", "link"=&gt;"http://www.bench.co.uk/womenswear/underwear/basic-girl-boxer/WH001/"}, {"price"=&gt;"45.00", "name"=&gt;"OSPREY TRAINER", "description"=&gt;"Lace up trainers Bench logo on tongue and back of heelBench logo on end of trainer", "link"=&gt;"http://www.bench.co.uk/menswear/footwear/osprey-trainer/WH001-BL081/"}, {"price"=&gt;"45.00", "name"=&gt;"OSPREY TRAINER", "description"=&gt;"Lace up trainers Bench logo on tongue and back of heelBench logo on said of trainer", "link"=&gt;"http://www.bench.co.uk/menswear/footwear/osprey-trainer/WH001-GR128/"}, {"price"=&gt;"90.00", "name"=&gt;"META TRENCH", "description"=&gt;"Vintage look leather bootLace upFabric sidesPull on tab on heel", "link"=&gt;"http://www.bench.co.uk/womenswear/footwear/meta-trench/BK001/"}]
  (^ Truncated)
  </code></pre>
  
  <p>Can someone tell me how I can access elements of the array? Loop through so I can get <code>@products.price</code>, <code>@products.description</code> etc?</p>
  
  <p>Edit: I've tried <code>@products[0]</code>, <code>products[0]</code>, I've tried printing key/value pairs without any luck.</p>
  
  <p>I'm not asking you to do all the work, I think it's that there are a few concepts at work here - enough to keep me hitting brick walls.</p>
  
  <p>Part 2: Extra Credit!</p>
  
  <p>Based on the selected answer, this should work, right?</p>
  
  <pre><code> @products.each do |h|
     h.save
   end
  </code></pre>
  
  <p>I get: </p>
  
  <pre><code>NoMethodError: undefined method `save' for #&lt;Hash:0x10388c7d8&gt;
  </code></pre>