From: dblack@... Date: 2006-02-28T23:17:41+09:00 Subject: Re: Pine's book "Learning to Program" - Answer? Hi -- On Tue, 28 Feb 2006, woodyee wrote: > Thanks! NOW, I think I get it. Here's my program: > > # Write a program which asks for a person's favorite number. Have your > #program add one to the number, then suggest the result as a bigger and > > #better favorite number. > > > puts "What is your favorite number? " > num = gets.chomp > better = num.to_i + 1 > puts 'This is a better number: ' + better.to_s + '.' > > > Gregor's solution is compact (good thing) but it's too advanced for me > now. :-) > What is it? Looks like a Python concocted commented out dictionary to > me... :-) > Thanks again! Gregor is using string interpolation, to insert the expression num + 1 into the output string. String interpolation works like this: "This is a string with #{2 + 2} inside it." which will print: This is a string with 4 inside it. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black