From: Pieter Hugo Date: 2009-11-26T16:39:44+09:00 Subject: Re: Difference between << and += for Strings and Arrays. Bug? Hi Robert (and everyone else) - thanks for the well reasoned responses. I'll get the hang of it I'm sure > Why do you want to have two copies of your Array? I have a setup where I have Folder objects. A folder can have many other children (members) as sub folders, but it can also have many other folders as parents (groups it belongs to). I get this done via a crosslink table. When creating a new parent-child relationship I need to make sure that the child is not somehow an ancestor or the parent I am trying to subordinate it to (as I need to avoid circular reference) So I wrote the folder function: def ancestors ancestors = self.groups #all the immediate parents are obviously ancestors scanfolders = [] #set up a stack to iterate through, #looking for grandparents etc scanfolders += ancestors #the stack starts with the current ancestors if !scanfolders.nil? then while scanfolders.length > 0 do # while there are items on the stack scanitem = scanfolders.pop # get the last one and reduce the stack if scanitem then if !scanitem.groups.nil? then #if this item has parents #add them to the stack scanfolders += scanitem.groups scanfolders.uniq! ancestors += scanitem.groups #and record this item as an #ancestor ancestors.uniq! end end end end return ancestors end So - to answer the question - I need to arrays that are initially the same (direct parents), But the one will eventually contain all ancestors and the other will be empty after iterating through all ancestors and testing them for further ancestors. I should just replace scanfolders = [] scanfolders += ancestors with scanfolders = ancestors.dup Regards Pieter -- Posted via http://www.ruby-forum.com/.