Created
November 11, 2009 00:07
-
-
Save robhanlon22/231419 to your computer and use it in GitHub Desktop.
recursive implementation of Array#flatten
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 Array | |
alias_method :flatten_old, :flatten | |
def flatten(result = []) | |
inject(result) do |memo, item| | |
item.kind_of?(Array) and item.flatten(memo) or memo << item | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment