From: Phrogz Date: 2007-01-21T03:15:06+09:00 Subject: Re: Proper way to either create or append to an array? Robert Klemme wrote: > Since you're using a Hash the block constructor is the most elegant > solution IMHO: > > def initialize > @foo = Hash.new {|h,k| h[k]=[]} > ... > end To be clear for those unfamiliar with this: any time you ask for the value of a key that doesn't exist, the block will be called (which creates a new empty array). This means you can never see this particular Hash has a key, since: if @foo[ :bar ] will always succeed, and create a (possibly unwanted) array instance in the process.