I'm just starting my adventure with Ruby, and I have a problem. I've completed Codecademy's Ruby course, so I'm not THAT green, but i still don't know too much. Anyway. How can you update a specific value with an equation? Like, here is what I'm trying to do with the following hash:
hash = { "s1" => 2, "s2" => 3 }
What I want to do next, is get input via gets.chomp to get the key, and then acquire the amount to add to value (via gets.chomp as well). Here's what I have unsuccessfully tried:
name = gets.chomp
value = gets.chomp.to_i
hash.each do |x, y|
if x == name
y == y + value
else
puts "nope"
end
end
I have also tried messing around with Hash#update but with no luck.
Can anyone help please? I've been stuck on it for like 3 hours already :/
Cheers, Boberczus