#!/usr/bin/env ruby -w # # Table of Contents # "Learn to Program" by Chris Pine, p. 63 # toc = [ [1, 'Getting Started', 1], [2, 'Numbers', 9], [3, 'letters', 13], ] width = 80 column = width / 3 sub_column = column / 2 puts 'Table of Contents'.center(width) puts toc.each do | line | (chapter, title, page) = line chapter = 'Chapter ' + chapter.to_s print chapter.ljust(column), title.ljust(column), 'page '.ljust(sub_column), page.to_s.rjust(sub_column), "\n" end puts