From: Matt Armstrong Date: 2002-01-11T07:27:18+09:00 Subject: dup, clone, and "deep copy" I see that Object#dup creates a new object and copies its instance variables (no deep copy). Object#clone creates a new object but much more state is retained (singleton methods, I'm not sure what else). In sub classes, are there any conventions for how deep a copy dup and clone should make? Say I have a class: class Foo def initialize @array = [] @hash = {} end private def dup_self @array = @array.dup @hash = @hash.dup self end end I assume that these are reasonable? class Foo def dup temp = super temp.dup_self end def clone temp = super temp.dup_self end def deep_dup Marshall::load(Marshall::dump(dup)) end def deep_clone Marshall::load(Marshall::dump(self)) end end -- matt