When we initialize an array of arrays using
ar = Array.new(2, [0, -1])
It creates an array which looks like [[0, -1], [0, -1]]
But when we change the value in the inner array, it gets reflected in all elements of the array.
ar[0][0] = 5
puts ar
[[5, -1], [5, -1]]
Seems the same object is getting inserted into each index of the outer array. What is the correct way to prevent this?