Hello people!
I am very new to Ruby. Yesterday I bought very nice book about Ruby and
immediately started learning. Now I have little problem
The exercise is to display text like this:
Table of Contents
Chapter 1: Getting Started page 1
Chapter 2: Numbers page 9
Chapter 3: Letters page 13
but my text always looks like this:
Table of Contents
Chapter 1: Getting Started page 1
Chapter 2: Numbers page 9
Chapter 3: Letters page 13
My code is:
line_width = 50
str1 = âTable of Contentsâ
str_chap1 = âChapter 1: Getting Startedâ
str_chap2 = âChapter 2: Numbersâ
str_chap3 = âChapter 3: Lettersâ
str_page1 = âpage 1â
str_page9 = âpage 9â
str_page13 = âpage 13â
puts(str1.center(line_width))
putsââ
puts(str_chap1.ljust(line_width/2) + str_page1.rjust(line_width/2))
puts(str_chap2.ljust(line_width/2) + str_page9.rjust(line_width/2))
puts(str_chap3.ljust(line_width/2) + str_page13.rjust(line_width/2))
What should I do to vertically align strings )âpage 1â, âpage 9â and
âpage 13â)?
P.S. If you know some more better way to write this, I would be happy to
see it (and to try to understand it )
P.S. Sory if this is a stuped question.