From: Jason Roelofs Date: 2006-09-25T23:40:26+09:00 Subject: Re: Object initialization problem ------=_Part_28238_10115479.1159195223164 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Doh! I'm getting caught up in the cooler features of Ruby and forgetting the simple stuff. David's got it right. Jason On 9/25/06, dblack@wobblini.net wrote: > > Hi -- > > On Mon, 25 Sep 2006, Jason Roelofs wrote: > > > 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. > > There's also DRR (Don't Repeat Ruby :-) Hashes are already good at > this stuff (see my previous response). > > > David > > -- > David A. Black | dblack@wobblini.net > Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] > DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] > [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com > [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org > > ------=_Part_28238_10115479.1159195223164--