I have an array of hashes that will likely have similar keys but different values. When populating them, I notice that trying to update one hash updates them all.
test = Array.new(4, {})
test[0][:test] = 1
test
=> [{:test=>1}, {:test=>1}, {:test=>1}, {:test=>1}]
If I manually write out the array, this does not happen.
test = [{}, {}, {}, {}]
test[0][:test] = 1
test
[{:test=>1}, {}, {}, {}]
Can anyone explain why this happening and what the difference is between the two?