Created
December 5, 2012 20:27
-
-
Save thomasklemm/4219200 to your computer and use it in GitHub Desktop.
Table of Contents - Structured Layout in Ruby
This file contains hidden or 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
## | |
# 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