Skip to content

Instantly share code, notes, and snippets.

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]]