Skip to content

Instantly share code, notes, and snippets.

@schell
Last active December 16, 2015 16:10
Show Gist options
  • Save schell/5461557 to your computer and use it in GitHub Desktop.
Save schell/5461557 to your computer and use it in GitHub Desktop.
learning ruby vtable opening up array
puts 'VTable format'
class Array
def print_vtable(cols)
rows = (self.length.to_f / cols).ceil
self.map { |index|
x = index % cols
y = index / cols
x * rows + y
}
end
end
# print_vtable on array
(0...17).to_a.print_vtable(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment