Skip to content

Instantly share code, notes, and snippets.

@nelstrom
Created April 25, 2009 11:10
Show Gist options
  • Save nelstrom/101586 to your computer and use it in GitHub Desktop.
Save nelstrom/101586 to your computer and use it in GitHub Desktop.
class Array
# Handy when outputing a list in two columns, such as:
#
# A B A C A C A D
# B B D B E
# C
#
def columnize
if size <= 1
[ self, [] ]
elsif size % 2 == 0
[self[0...size/2], self[size/2..-1]]
else
[self[0..size/2], self[size/2+1..-1]]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment