Skip to content

Instantly share code, notes, and snippets.

@celbaz
Created November 13, 2014 23:27
Show Gist options
  • Save celbaz/3b74d888101848ab9d1c to your computer and use it in GitHub Desktop.
Save celbaz/3b74d888101848ab9d1c to your computer and use it in GitHub Desktop.
Recursive Deep Copying (Ruby)
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