class Object

This file extends some Ruby core classes to add deep-copying support. I’m aware of the commonly suggested method using Marshal:

class Object

def deep_copy
  Marshal.load(Marshal.dump(self))
end

end

But just because I program in Ruby, I don’t have to write bloatware. It’s like taking a trip to the moon and back to shop groceries at the store around the corner. I’m not sure if I need more special cases than Array and Hash, but this file works for me.

In certain cases the full deep copy may not be desired. To preserve references to objects, you need to overload deep_clone and handle the special cases. Alternatively, an object can be frozen to prevent deep copies.