Created
April 25, 2009 11:10
-
-
Save nelstrom/101586 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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