matrix = Array.new(2, Array.new(2, 0))
=> [[0, 0], [0, 0]]
matrix[0][0] = 5
=> 5
matrix
=> [[5, 0], [5, 0]]
Why does it happen? While modifing the assignment I get the following result:
matrix = [[0, 0], [0, 0]]
=> [[0, 0], [0, 0]]
matrix[0][0] = 5
=> 5
matrix
=> [[5, 0], [0, 0]]