From: Gavin Sinclair Date: 2003-01-30T13:27:58+09:00 Subject: Re: A simple program but strange output On Thursday, January 30, 2003, 3:13:43 PM, Maggie wrote: > Hi there, > I wrote a simple program to enumerate an array. The code is as below: > class Test > def initialize > @x=[0,1,2] > @tem=@x > @y=@x > y=del(@tem) > printf "#{@x}\n" > printf "#{@y}\n" > end > def del(x) > x.delete_at(0) > return x > end > end > a=Test.new > But the output is : > 12 > 12 > Why @x and @y are changed? Is there anyone can tell me how to deal with > this problem? @x, @y, and @tem are all the same object, viewed through different variables. Since you use printf, I presume you know C. They are like pointers. BTW printf "#{@x}\n" == puts @x Gavin