Skip to content

Instantly share code, notes, and snippets.

@chris-79
Created May 22, 2013 20:02
Show Gist options
  • Save chris-79/5630453 to your computer and use it in GitHub Desktop.
Save chris-79/5630453 to your computer and use it in GitHub Desktop.
a = [1,2,3,4,5]
# 2 new arrays
left,right = a.each_slice( (a.size/2.0).round ).to_a
# left == [1, 2, 3]
# right == [4, 5]
# make array 2-dimensional
a.each_slice( (a.size/2.0).round ).to_a
# a == [[1, 2, 3], [4, 5]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment