Rubymonk - Iterating over a hash
<p>Ruby Monk (Section: 4.1 - Hashes) has an exercise about a restaurant and increasing the price by 10%. The directions on the site are:</p>
<blockquote>
<p>Use the each method to increase the price of all the items in the restaurant_menu by 10%.</p>
<p>Remember: in the previous example we only displayed the keys and values of each item in the hash. But in this exercise, you have to modify the hash and increase the value of each item.</p>
</blockquote>
<p>My main question is, why does this code pass:</p>
<pre><code>restaurant_menu = { &quot;Ramen&quot; =&gt; 3, &quot;Dal Makhani&quot; =&gt; 4, &quot;Coffee&quot; =&gt; 2 }
restaurant_menu.each do |item, price|
  restaurant_menu[item] = price + (price * 0.1)
end
</code></pre>
<p>vs. this?</p>
<pre><code>restaurant_menu = { &quot;Ramen&quot; =&gt; 3, &quot;Dal Makhani&quot; =&gt; 4, &quot;Coffee&quot; =&gt; 2 }
# write the each loop here. 
restaurant_menu.each do | item, price |
  puts &quot;#{item}: $#{price + (price * 0.1)}&quot; 
end
</code></pre>
<p>I'm assuming it has something to do with [item] which I'm assuming is an array(?) and &quot;price + (price * 0.1)&quot; being added to the [item] array.</p>
<p>Secondarily, is it possible that the string interpolation could be making the above code not pass . . . Thanks in advance for anything in helping me better understand this code.</p>