I have created the following code as part of an excercise in a Ruby tutorial I am trying:
title = ['Chapter 1: Numbers','Chapter 2: Letters','Chapter 3: Variables']
pages = ['Page 1','page 72','page 118']
linewidth = 40
header = '*Table of Contents*'
puts header.center linewidth
puts
puts ((title[0]).ljust linewidth/2) + ((pages[0]).rjust linewidth/2)
puts ((title[1]).ljust linewidth/2) + ((pages[1]).rjust linewidth/2)
puts ((title[2]).ljust linewidth/2) + ((pages[2]).rjust linewidth/2)
My question is can the above be done without clarifying which part of the array to display? i.e. can I just, in one bit of code, get it to list all titles and all pages in the array in order? If so how would this be done?
You can output list like this: