Skip to content

Instantly share code, notes, and snippets.

@jackdempsey
Created September 16, 2008 22:23
Show Gist options
  • Save jackdempsey/11151 to your computer and use it in GitHub Desktop.
Save jackdempsey/11151 to your computer and use it in GitHub Desktop.
From 52d5bcc85b0cb1d8a86b471418818bcca27071a6 Mon Sep 17 00:00:00 2001
From: Jack Dempsey <[email protected]>
Date: Tue, 16 Sep 2008 18:25:23 -0400
Subject: [PATCH] Add in deep_clone method
---
lib/extlib/object.rb | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/lib/extlib/object.rb b/lib/extlib/object.rb
index 2414fe4..2dd985f 100644
--- a/lib/extlib/object.rb
+++ b/lib/extlib/object.rb
@@ -136,6 +136,13 @@ class Object
self.dup
end
+ # Performs a deep clone of an object
+ #
+ # @return <Object>
+ def deep_clone
+ Marshal::load(Marshal.dump(self))
+ end
+
# @param arrayish<#include?> Container to check, to see if it includes the object.
# @param *more<Array>:: additional args, will be flattened into arrayish
#
--
1.5.5.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment