From: Florian Gilcher Date: 2010-04-08T03:01:41+09:00 Subject: Re: Dissapearing data from array On Apr 7, 2010, at 7:47 PM, Noé Alejandro wrote: > Hi all. > > I have the next problem. > > a = %w(a b) > z = %w(1) > a.insert(1, z) > puts a > a > 1 > b Try puts a.inspect #=> ["a", ["1"], "b"] > > z.clear > puts a > a > b puts a.inspect #=> ["a", [], "b"] > > Oopss... where "1" is? what happened? what can I do to keep "1" when I > clear the array (z)? Ruby uses references. So a.insert(1, z) inserts a reference to z at position 1 in the array. So once you clear z, it will be cleared noticed by everyone referring to it - a, in this case. Regards, Florian