From: Jason Roelofs Date: 2008-04-15T03:02:48+09:00 Subject: Re: Mutable member variables -- surprising behavior On Mon, Apr 14, 2008 at 1:43 PM, ara.t.howard wrote: > > On Apr 14, 2008, at 11:34 AM, Jason Roelofs wrote: > > > > > # Always give a copy of the array, that way the internal @elems > > # array is never changed. > > def elems > > @elems.clone > > end > > end > > > > does not work, neither does dup. both are rather shallow in ruby. if you > *really* want a copy you need > > Marshal.load(Marshal.dump(@elems)) > > otherwise you'll end up with subtle bugs when the array is cloned, but > elements inside of it, or deeper, are not. > > fyi. > > a @ http://codeforpeople.com/ > -- > we can deny everything, except that we have the possibility of being > better. simply reflect on that. > h.h. the 14th dalai lama > Eep, yeah, I forgot about that. #dup and #clone won't work, sorry for that misinformation. Jason