From: Jason Roelofs Date: 2006-09-25T23:28:09+09:00 Subject: Re: Object initialization problem ------=_Part_27892_26708574.1159194486407 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline class Hash def increment_word_count(key) self[key] ||= 1 self[key] += 1 end end count = Hash.new count.increment_word_count(word) Of course, if you can think of a better method name, but this will help with DRYness. Jason On 9/25/06, Vimal wrote: > > Hi > Say I have a Hash, and an instance called wordcount, that maps strings > to a number count, that counts the occurance of the word. > > I do > > count = Hash.new > count[word]++ if count[word] > count[word]=1 unless count[word] > > everytime! Is there a simple way to do it? > > Thanks :) > Vimal > > ------=_Part_27892_26708574.1159194486407--