title: Rails syntax error assigning a variable with each loop
body: <p>I'm trying to create a list of recipients to send in an external request by assigning it to a variable by doing the following:</p>
  
  <pre><code>recipients = @items.each do |item|
    {"email"=&gt;"#{Recipient.find_by_id(item.recip_id).email}", "amount"=&gt;"#{item.price}"},
  end
  </code></pre>
  
  <p>but I'm getting this error:</p>
  
  <pre><code>syntax error, unexpected ',', expecting '}'
  </code></pre>
  
  <p>I know that what I've done is not the right syntax. I'm kind of a Ruby newbie, so can someone help me figure out the correct syntax here?</p>
  
  <p>EDIT: Thanks for the input. But what if I need to do two hashes for each item?</p>
  
  <pre><code>recipients = @items.map do |item|
    {"email"=&gt;"#{Recipient.find_by_id(item.recip_id).email}", "amount"=&gt;"#{item.price}"},
    {"email"=&gt;"#{Store.find_by_id(item.recip_id).email}", "amount"=&gt;"#{item.price}"}
  end
  </code></pre>