|
States are arrays, when you define an variable equal an array, it stores the *whole* array, including it memory address. (This happens with many types of objects in fact)
So if you make
@array_1 = [1,2,3] @array_2 = @array_1
any change you do to @array_2 will take effect on @array_1and vice versa, since they're basically the same object
To solve that, you can make a duplicate of the array
@array_1 = [1,2,3] @array_2 = @array_1.dup that way, the array will have the same value, but WILL NOT be the same. So the chances won't affect both.
The second alternative you posted works because you're not assing the array the same as another, but simply making a new array (@old_stats[i][2] = []) and adding values in the same order as the other one.
__________________________
|