From: Lars Christensen Date: 2002-05-29T21:37:40+09:00 Subject: Re: Idioms On Wed, May 29, 2002 at 08:58:59PM +0900, Stephan J. Schmidt wrote: > Could someone point me to idioms about ruby, e.g. > something shorter to > > if not hash.key?(key) > hash[key] << value > end We have started a page here: http://www.rubygarden.org/ruby?RubyIdioms The above could be turned into hash[key] ||= [value] but if you always want to add the value, and make sure there is a list in the hash you could do this: (hash[key] ||= []) << value Some would argue this is not particular Ruby-ish, but I find such shortcuts very convinient. -- Lars Christensen