Skip to content

Instantly share code, notes, and snippets.

@timrandg
Created January 8, 2012 06:31
Show Gist options
  • Save timrandg/1577478 to your computer and use it in GitHub Desktop.
Save timrandg/1577478 to your computer and use it in GitHub Desktop.
public
def rec_flatten
collection ||= []
return collection if self == []
if self.class != Array
return collection << self
end
collection + self[0].rec_flatten + self[1..-1].rec_flatten
end
[[3],1,[2],[[[[[[1]],4,[4]]]],2]].rec_flatten # => [3, 1, 2, 1, 4, 4, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment