when you assign one array it just copies the reference and both of them point to the same reference.
so a change in one is reflected when you print either of them.
orig_array = [1,2,3,4]<br>
another_array = orig_array
puts orig_array.unshift(0).inspect
puts another_array.inspect
Output:
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4]
To avoid this you can use Marshal to copy from original array without impacting the object to which it is copied.
Any changes in the original array will not change the object to which it is copied.
orig_array = [1,2,3,4]<br>
another_array = Marshal.load(Marshal.dump(orig_array))
puts orig_array.unshift(0).inspect
puts another_array.inspect
Output:
[0, 1, 2, 3, 4]
[1, 2, 3, 4]
I have already pasted this answer in another thread. Change value of a cloned object