Skip to content

Instantly share code, notes, and snippets.

@clauda
Created May 20, 2016 02:20
Show Gist options
  • Save clauda/9e736346a117326400d7adaf033f1189 to your computer and use it in GitHub Desktop.
Save clauda/9e736346a117326400d7adaf033f1189 to your computer and use it in GitHub Desktop.
Ruby #flat
class Array
def flat
each_with_object([]) do |element, init|
init.push *(element.is_a?(Array) ? element.flat : element)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment