I want to have an array, say 5x5 with all nils unless set to something
else.
However, when I set m[0][0] to 0 … all 0 indices are set to zero…
Hmm…
never asked for that to be the case.
There’s some funky stuff going on here.
irb(main):001:0> n = 5
=> 5
irb(main):002:0> m = [[nil]*n]*n
=> [[nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil], [nil, nil,
nil,
nil, nil], [nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil]]
irb(main):003:0> m[0][0] = 0
=> 0
irb(main):004:0> m
=> [[0, nil, nil, nil, nil], [0, nil, nil, nil, nil], [0, nil, nil, nil,
nil], [0, nil, nil, nil, nil], [0, nil, nil, nil, nil]]
Any ideas?