Last active
November 16, 2016 22:20
-
-
Save jgonzalezd/2164652507c85c53facea4090d7e5658 to your computer and use it in GitHub Desktop.
Array class gets a new flatten method
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
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