Chris Carter
5/23/2007 2:52:00 AM
On 5/22/07, Mike Steiner <mikejaysteiner@gmail.com> 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