title: Appending keys to a hash in an each loop
body: <p>I am walking through a rails Hash tutorial and got stuck on how to manipulate hashes in a loop. I have got a hash called <code>products</code>:</p>
  
  <pre><code>products = Product.where(category: 'electronics', price: 10000).pluck_to_hash(:id)
  # =&gt; [{:id=&gt;23}, {:id=&gt;12}, {:id=&gt;108}]
  </code></pre>
  
  <p>and my aim is to iterate through it like this: </p>
  
  <pre><code>products.each do |p|
    @store = Store.where(product: p[:id], country: gb).pluck_to_hash(:store_code, :manager_name)
  end
  </code></pre>
  
  <p>and store all 6 store results in the <code>@store</code> instance variable so I can pass it to view. </p>
  
  <p>Using <code>=</code> only ends up with one
  store and not all 6 stores I'm trying to get. <code>&lt;&lt;</code> is only for arrays. </p>
  
  <p>I also tried </p>
  
  <pre><code>@store.merge!(Store.where(product: p[:id], country: gb).pluck_to_hash(:store_code, :manager_name))
  </code></pre>
  
  <p>and got:</p>
  
  <blockquote>
    <p>undefined method `merge!' for nil:NilClass</p>
  </blockquote>
  
  <p>Then I declared an empty Hash before the loop:</p>
  
  <pre><code>@store = {} 
  </code></pre>
  
  <p>and that gave: </p>
  
  <blockquote>
    <p>no implicit conversion of Array into Hash</p>
  </blockquote>
  
  <p>Any guidance on how to iteratively store those keys in <code>@store</code> varaible will be greatly appreciated. </p>
  
  <p>Please note that this question isn't about model associations; it's specific to Hash manipulations.</p>