Created
October 31, 2014 16:27
-
-
Save macabreb0b/640af0d5386beffb8996 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Enumerable | |
def deep_dup | |
self.map do |*elements| | |
if element.is_a?(Enumerable) | |
element.deep_dup | |
else | |
elements.map do |element| | |
begin | |
duplicate = element.class.allocate | |
duplicate.send(:initialize_copy, element) | |
duplicate | |
rescue | |
element | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment