Skip to content

Instantly share code, notes, and snippets.

@robhanlon22
Created November 11, 2009 00:07
Show Gist options
  • Save robhanlon22/231419 to your computer and use it in GitHub Desktop.
Save robhanlon22/231419 to your computer and use it in GitHub Desktop.
recursive implementation of Array#flatten
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