From: Chris Carter Date: 2007-05-23T11:51:51+09:00 Subject: Re: problem appending to arrays in a hash of arrays On 5/22/07, Mike Steiner wrote: > I'm trying to create a hash with each element being an array (initially > empty), and I've tried a few variations to get what I want. Why don't the > last 2 lines work? > > h = Hash.new ( Array.new ) > h["abc"] = h["abc"] + [ "foo" ] # this works > h["abc"] << "foo" # this doesn't > h["abc"].push ( "foo" ) # this doesn't either > > (Note: the above code isn't the actual code I'm using, but a simplified > version.) > > Mike Steiner > >> g = Hash.new {|h,k| h[k]=[]} => {} >> g["abc"] << :foo => [:foo] >> g => {"abc"=>[:foo]} -- Chris Carter concentrationstudios.com brynmawrcs.com