このコード:
[{:id => 1,:key => 3},{:id => 2,:key => 4},{:id => 3, :key => 5}].
inject(Hash.new([])){|h,i| h[i[:key]] << i; h}
戻り値:
{}
これの間:
[{:id => 1,:key => 3},{:id => 2,:key => 4},{:id => 3, :key => 5}].
inject(Hash.new([])){|h,i| h[i[:key]] += [i]; h}
戻り値:
{3=>[{:id=>1, :key=>3}, {:id=>3, :key=>3}], 4=>[{:id=>2, :key=>4}]}
最初のケースが同じように機能しないのはなぜですか?