From: Jim Freeze Date: 2001-05-18T03:08:55+09:00 Subject: [ruby-talk:15335] Re: How to clone an object? Sorry for responding to my own post, but the text below may be a bit more clear. I have run across the following interesting situtation: class K attr_accessor :a def initialize @a = [1,2] end end k1 = K.new k2 =k1.clone ## Choose one of the next two line k2.a = [4,5] -> # # k2.a[0] = 5 -> # -> # puts k1.inspect puts k2.inspect ---- I guess that k2.a = is assigning a new array to k2.a while k2.a[n] = keeps the same array object in k2.a The question is, how do I get a copy of k2 where k2.a is a copy of k1.a and not a reference? Thanks ========================================================= Jim Freeze jim@freeze.org --------------------------------------------------------- No comment at this time. http://www.freeze.org =========================================================