I'm going through the RubyMonk exercises on hashes The exercise is to change the prices of the restaurant_menu by 10%. My solution was incorrect. I iterated over each tuple and changed just the price value.
restaurant_menu = { "Ramen" => 3, "Dal Makhani" => 4, "Coffee" => 2 }
restaurant_menu.each do |item, price|
price = price * 1.1
end
The correct solution is here. restaurant_menu = { "Ramen" => 3, "Dal Makhani" => 4, "Coffee" => 2 } restaurant_menu.each do |item, price| restaurant_menu[item] = price + (price * 0.1) end
I don't understand why the extra call to the hash is necessary if I'm already iterating over the price values.