Marry Jane Marry Jane - 4 months ago 8
Ruby Question

How to increase 1 number value for a Hash?

@participants[id]={nick: nick, points: 0}
=> {"1"=>{:nick=>"Test", :points=>0}

I want to add in points for ID
1
. I did
@participants["1"].points+=1
but it does not work. How do I make it to add 1 each time?

Answer

@participants["1"] is also an hash, so

@participants["1"][:points] += 1
Comments