From: "Brian Schröder" Date: 2004-12-11T04:59:10+09:00 Subject: How to make a deep copy of an object (Searching for Idiom) Hello Group, I sometimes which to make a deep copy of an object. I know I could use Marshal, but thats slow so I want to write a routine #deep_copy. (Or should I overwrite #dup ?) Now the question is, how do you write those. I could use this: class A ... def deep_copy result = self.dup result.field1 = self.field1.deep_copy ... end end or class A def initialize(field1 = 'default value', ...) @field1 = field ... end def deep_copy self.new(@field1.deep_copy) end end Which allows me to use instance variables. Is there something more elegant. What do you prefer? Am I on the right track? Best regards, Brian -- Brian Schr�der http://www.brian-schroeder.de/