Consider this code:
h = Hash.new(0) # New hash pairs will by default have 0 as values h[1] += 1 #=> {1=>1} h[2] += 2 #=> {2=>2}
You're specifying that the default value for the hash is a reference to that particular (initially empty) array.
I think you want:
h = Hash.new { |hash, key| hash[key] = []; } h[1]<<=1 h[2]<<=2
That sets the default value for each key to a new array.