When I try to pop an element from an array, it pops. When I assign that array to another variable before popping and then if I pop, the pop operation affects both the arrays.
For example:
ruby-1.9.2-p290 :339 > a= [1,2,3]
=> [1, 2, 3]
ruby-1.9.2-p290 :340 > b = a
=> [1, 2, 3]
ruby-1.9.2-p290 :341 > a
=> [1, 2, 3]
ruby-1.9.2-p290 :342 > b
=> [1, 2, 3]
ruby-1.9.2-p290 :343 > a.pop
=> 3
ruby-1.9.2-p290 :344 > a
=> [1, 2]
ruby-1.9.2-p290 :345 > b
=> [1, 2] #WHY?
ruby-1.9.2-p290 :346 > x = [1,2,3]
=> [1, 2, 3]
ruby-1.9.2-p290 :347 > y = x
=> [1, 2, 3]
ruby-1.9.2-p290 :348 > z = x
=> [1, 2, 3]
ruby-1.9.2-p290 :349 > y
=> [1, 2, 3]
ruby-1.9.2-p290 :350 > z
=> [1, 2, 3]
ruby-1.9.2-p290 :351 > y.pop
=> 3
ruby-1.9.2-p290 :352 > y
=> [1, 2]
ruby-1.9.2-p290 :353 > z
=> [1, 2] # WHY?
ruby-1.9.2-p290 :354 > x
=> [1, 2]
ruby-1.9.2-p290 :355 >
If I use pop, all the variables are affected. How do I keep the original array and pop from the other one only?