Skip to content

Instantly share code, notes, and snippets.

@thomasklemm
Created December 5, 2012 20:27
Show Gist options
  • Save thomasklemm/4219200 to your computer and use it in GitHub Desktop.
Save thomasklemm/4219200 to your computer and use it in GitHub Desktop.
Table of Contents - Structured Layout in Ruby
##
# A ruby-powered table of contents layout
words = %w(we are the world lets make it a better place we are the world)
words.each_with_index {|word, page| puts word.ljust(10, '.') + (page*page).to_s.rjust(3, '.')}
# => Output
# we..........0
# are.........1
# the.........4
# world.......9
# lets.......16
# make.......25
# it.........36
# a..........49
# better.....64
# place......81
# we........100
# are.......121
# the.......144
# world.....169
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment