From: Robert Klemme Date: 2007-01-21T03:10:06+09:00 Subject: Re: Proper way to either create or append to an array? On 20.01.2007 18:55, Adam Block wrote: > Hi all. > > Let's say I want to either create a new named array or append to that > array if it already exists. Is there a more elegant way of doing the > following? > >>> @foo[:bar].nil? ? foo[:bar] = ["snafu"] : foo[:bar] << "snafu" 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 def other_method ... @foo[:bar] << "snafu" ... end Kind regards robert