Created
November 13, 2014 23:27
-
-
Save celbaz/3b74d888101848ab9d1c to your computer and use it in GitHub Desktop.
Recursive Deep Copying (Ruby)
This file contains hidden or 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 Array | |
def deep_dup | |
self.map do |el| | |
if !el.is_a? Array | |
el | |
elsif self.none? {|el| el.is_a? Array} | |
el.map {|el2| el2} | |
else | |
el.deep_dup | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment