Kaye Ng wrote:
#Run this code
x=[2,6,5,9]
y = x
puts x
puts
puts y
putsx=[1,2,3,4]
puts x
puts
puts y
-------------------------------------
#this alsox=[2,6,5,9]
y = x
puts x
puts
puts y
putsx.pop
puts x
puts
puts y
---------------------------I understand the first code, y was still pointing to [2,6,5,9]
but isn't the second code similar? shouldn't y still be [2,6,5,9] ?Or is the method pop an exemption in this case?
Beginner here. Thanks everyone!
In the second snippet x.pop removes the last
element, leaving x=[2,6,5], and y points to
the modified array.
HTH gfb
ยทยทยท
--
Posted via http://www.ruby-forum.com/\.