Recently I attempted to append a number to one of the nested arrays in my script. I expected only the nested array at the specified index to have the number appended to it, but what actually happened was that all of the nested arrays had the number appended to them.
This behaviour seems very odd, why do ruby arrays function this way?
irb(main):001:0> [1,2,3].push 3
=> [1, 2, 3, 3]
irb(main):002:0> layered = [[]] * 5
=> [[], [], [], [], []]
irb(main):003:0> layered[0] << 2
=> [2]
irb(main):004:0> layered
=> [[2], [2], [2], [2], [2]]
irb(main):005:0>