<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'A Few Things to Try: Table of Contents +' | Pragmatic Forums</title>
    <link>http://fora.pragprog.com/forums/6/topics/386</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>A Few Things to Try: Table of Contents + posted by Domingo Valls @ Sun, 24 Aug 2008 21:17:32 -0000</title>
      <description>&lt;p&gt;How about this, with a 2-dimensional array:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
lineWidth = 60
toc = [ [1, "Numbers", 1], [2, "Letters", 72], [3, "Variables", 118] ]
puts 'Table of Contents'.center(lineWidth)
puts ''
toc.each do |line|
  izquierda = 'Chapter ' + line[0].to_s + ': ' + line[1]
  derecha = 'page ' + line[2].to_s
  puts izquierda.ljust(lineWidth/2) + derecha.rjust(lineWidth/2)
end
&lt;/code&gt;</description>
      <pubDate>Sun, 24 Aug 2008 21:17:32 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:6:386:4306</guid>
      <author>Domingo Valls</author>
      <link>http://fora.pragprog.com/forums/6/topics/386</link>
    </item>
    <item>
      <title>A Few Things to Try: Table of Contents + posted by Jeff Townsend @ Mon, 30 Jun 2008 08:14:20 -0000</title>
      <description>&lt;p&gt;I&amp;#8217;m not sure if this is even close to what the author had in mind, but it worked for me:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
line_width = 40

table_of_contents = ["1. Intro".ljust(line_width/2), "2. Middle".ljust(line_width/2), "3. End".ljust(line_width/2), "Page 1".rjust(line_width/2), "Page 5".rjust(line_width/2), "Page 10".rjust(line_width/2), "Table of Contents".center(line_width)]

puts(table_of_contents[6])
puts(table_of_contents[0] + table_of_contents[3])
puts(table_of_contents[1] + table_of_contents[4])
puts(table_of_contents[2] + table_of_contents[5])

&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Mon, 30 Jun 2008 08:14:20 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:6:386:3403</guid>
      <author>Jeff Townsend</author>
      <link>http://fora.pragprog.com/forums/6/topics/386</link>
    </item>
    <item>
      <title>A Few Things to Try: Table of Contents + posted by Matt Rutledge @ Fri, 25 Apr 2008 18:28:08 -0000</title>
      <description>&lt;p&gt;Hi!&lt;br /&gt;Im new to programming (and Ruby of course) and am working through Chris Pine&amp;#8217;s tutorial as a starting point.  At the end of chapter 7 there is a &amp;#8216;A Few Things to Try&amp;#8217; project where you rewrite the Table of Contents program to utilize arrays.  Id like to house the information (ie Chapter Title and Page) in two seperate arrays and then cycle through code for each string in each array at the same time (hopefully this makes sense..).&lt;/p&gt;


	&lt;p&gt;Here is the code that Ive come up with (but of course doesnt work):&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
page_width = 50

contents = ['Chapter 1: Getting Started','Chapter 2: Numbers','Chapter 3: Letters']
pages = ['1','9','13']

contents.each do |content| and pages.each do |page|
puts(content.ljust(page_width/2)) + (page.rjust(page_width/2))
end
&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;

	&lt;p&gt;Im confident that Im going about this the wrong way&amp;#8230;any  hints?&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;THANKS&lt;/span&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 25 Apr 2008 18:28:08 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:6:386:2640</guid>
      <author>Matt Rutledge</author>
      <link>http://fora.pragprog.com/forums/6/topics/386</link>
    </item>
  </channel>
</rss>
