I have data for a table of contents:
array = [
['Chapter 1', 'Numbers', 1],
['Chapter 2', 'Letters', 72],
['Chapter 3', 'Variables', 118]
]
I am trying to display the contents of the array as a table like this:
Chapter 1 Numbers 1
Chapter 2 Letters 72
Chapter 3 Variables 118
Here is my code:
lineWidth = 80
col1Width = lineWidth/4
col2Width = lineWidth/2
col3Width = lineWidth/4
array.each do |i|
puts i[0].to_s.ljust(col1Width) + puts i[1].to_s.ljust(col2Width) + puts i[2].to_s.ljust(col3Width)
end
The problem is I keep getting this error:
chapter7-arrays.rb:48: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
puts i[0] + puts i[1] + puts i[2]
^
chapter7-arrays.rb:48: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
puts i[0] + puts i[1] + puts i[2]
All help appreciated.