I am working on learning some Hash operations in ruby. The code is about increasing each item's price by 10%. Why doesn't this code work?
restaurant_menu = { "Ramen" => 3, "Dal Makhani" => 4, "Coffee" => 2 }
restaurant_menu.each do |item, price|
price = price + (price * 0.1)
end
while this one does:
restaurant_menu = { "Ramen" => 3, "Dal Makhani" => 4, "Coffee" => 2 }
restaurant_menu.each do |item, price|
restaurant_menu[item] = price + (price * 0.1)
end
And any reasons as to why the latter is a better way to do it than the former as explained by @Mike Manfrin?