From: dblack@... Date: 2006-09-25T23:33:16+09:00 Subject: Re: Object initialization problem 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