Skip to content

Instantly share code, notes, and snippets.

@jkatz
Created February 13, 2009 05:50
Show Gist options
  • Save jkatz/63070 to your computer and use it in GitHub Desktop.
Save jkatz/63070 to your computer and use it in GitHub Desktop.
class Array
def columnize(n=1)
rows = []
y = (self.size / n.to_f).ceil
nmulti = (0...n).map {|n| y * n}
y.times do |x|
rows << self.values_at(*nmulti.map {|z| z + x}).compact
end
rows
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment