From: Tomas Brixi Date: 2001-09-04T16:49:35+09:00 Subject: [ruby-talk:20842] Re: modify hash during iteration Dave Thomas wrote: >Tomas Brixi writes: > >>Hello >> >>I have a question to following piece of code >>----------------- >>h = Hash.new >>#assign some data >> >>h.each do |pair| >> h[pair[0]] = new_value >>end >>----------------- >> >>is this the right way or are there better ways to do this >> > >I'm not sure what you're asking about. If it's the pair[0] call, then >you could do > > h = { "cat" => 1, "dog" => 99 } > > h.each do |key, | > h[key] += 1 > end > The question was about modifying the value of the key (pair[0]) Tom