Skip to content

Instantly share code, notes, and snippets.

@avdi
Created December 14, 2009 19:51
Show Gist options
  • Save avdi/256361 to your computer and use it in GitHub Desktop.
Save avdi/256361 to your computer and use it in GitHub Desktop.
# Single-level flatten
arr = [ [1], [2,3], [4, [5]] ]
# Too flat!
arr.flatten # => [1, 2, 3, 4, 5]
# Just right!
arr.inject([]){|a,e| a.concat(e)} # => [1, 2, 3, 4, [5]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment