Skip to content

Instantly share code, notes, and snippets.

@caius
Forked from jimneath/gist:312432
Created February 23, 2010 17:26
Show Gist options
  • Save caius/312437 to your computer and use it in GitHub Desktop.
Save caius/312437 to your computer and use it in GitHub Desktop.
# I want to turn this:
array = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# into this:
# [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
arr = []
array.each_slice(3) {|x| arr << x }
arr # => [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment