Assume, I have a two-dimensional array
irb(main):001:0> test_array = [[4,3],[4,5],[6,7]]
=> [[4, 3], [4, 5], [6, 7]]
I want to assign the last element of it to a variable
irb(main):002:0> test = test_array.last
=> [6, 7]
And I want to change it
irb(main):003:0> test[0] += 1
=> 7
Everything seems ok so far
irb(main):004:0> test
=> [7, 7]
But why the last element of the array has changed as well?
irb(main):005:0> test_array
=> [[4, 3], [4, 5], [7, 7]]
How do I avoid this?
ruby 2.0.0p481