Skip to content

Instantly share code, notes, and snippets.

@jgonzalezd
Last active November 16, 2016 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgonzalezd/2164652507c85c53facea4090d7e5658 to your computer and use it in GitHub Desktop.
Save jgonzalezd/2164652507c85c53facea4090d7e5658 to your computer and use it in GitHub Desktop.
Array class gets a new flatten method
module Recursive
class ::Array
def flatten_recursively
self.each_with_object([]) do |item, flattened|
item.is_a?(Array) ? flattened += item.flatten_recursively : flattened.push item
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment