At 2009-09-10 09:16PM, "7stud --" wrote:
>  7stud -- wrote:
> > h = Hash.new([])
> > 
> > h["A"] =  h["A"] << 10  #==>[10]
> > 
> > h["B"] = h["B"] << 20   #==>[20]
> > 
> > Look what happens:
> > 
> > 
> > p h
> > 
> > {"A"=>[10, 20], "B"=>[10, 20]}
> > 
>  
>  Yep, ruby hands you a reference to the same array over and over 
>  again...when you try to access non-existent keys.

While I thank you for takking the time, I can't say I'm enlightened by
your explanation.  What's the real difference between the blocks

bar = products.inject(Hash.new([])) {|h,p| h[p.category] << p; h}
baz = products.inject(Hash.new([])) {|h,p| h[p.category] += [p]; h}

Is it because += explicitly assigns a new object to the hash key?

-- 
Glenn Jackman
    Write a wise saying and your name will live forever. -- Anonymous