title: dynamically create a hash in ruby
body: <p>I am sure this is a question that has been asked before, but my research still hasn't led me to any conclusive answer. I am trying to create a standard key value pair in a loop. </p>
  
  <p>The code below iterates as expected, but it is only storing the last value. I understand why, because I am overwriting the <code>delivery_hash</code> variable each time by use of the <code>=</code>. I tried using the shovel operator that I have used for arrays, but that didn't work.</p>
  
  <pre><code>def calculate_job_delivery_costs
    delivery_hash = {}
    DELIVERY_COST_SCOPES.each do |scope|
      delivery_hash = { scope =&gt; job_delivery_costs.send(scope).inject(0) { |total, item| (total + item.cost_per_unit * item.hour_count) * item.quantity } }
    end
    delivery_hash
  end
  </code></pre>
  
  <p>my desired output is simply like this </p>
  
  <pre><code>"foo" =&gt; 234.32, 'bah' =&gt; 345.76, 'baz' =&gt; 33.87
  </code></pre>