From: Guten on 31 May 2010 23:53 [Note: parts of this message were removed to make it a legal post.] The final solution is look like this: puts 'What is your favourite number?' number = gets.chomp.to_i number +=1 puts 'Do you not think #{number} is a better number?' From: Josh Cheek on 1 Jun 2010 00:02 [Note: parts of this message were removed to make it a legal post.] On Mon, May 31, 2010 at 10:53 PM, Guten wrote: > The final solution is look like this: > > puts 'What is your favourite number?' > number = gets.chomp.to_i > number +=1 > puts 'Do you not think #{number} is a better number?' > You don't need chomp. "1\n".to_i # => 1 "1".to_i # => 1 From: Wes Bailey on 1 Jun 2010 02:05 ----- "Josh Cheek" wrote: > On Mon, May 31, 2010 at 10:53 PM, Guten wrote: > > > The final solution is look like this: > > > > puts 'What is your favourite number?' > > number = gets.chomp.to_i > > number +=1 > > puts 'Do you not think #{number} is a better number?' > > > > You don't need chomp. > > "1\n".to_i # => 1 > "1".to_i # => 1 Let's not forget our double quotes. Also why write so much code? puts 'What is your favorite number?' puts "Bah! #{gets.to_i + 1} is a better number!" Understand the #{...} is implicitly invoking to_s on the result so it can be displayed as part of the final string. From: Martin DeMello on 1 Jun 2010 04:06 On Tue, Jun 1, 2010 at 11:35 AM, Wes Bailey wrote:> > Let's not forget our double quotes.  Also why write so much code? Because when you're learning to program it's nice to have stuff teased apart into separate steps so that every line is doing just one simple thing, martin From: Wes Bailey on 1 Jun 2010 12:25 ----- "Martin DeMello" wrote: > On Tue, Jun 1, 2010 at 11:35 AM, Wes Bailey > wrote: > > > > Let's not forget our double quotes. Â Also why write so much code? > > Because when you're learning to program it's nice to have stuff > teased > apart into separate steps so that every line is doing just one simple > thing, > > martin Agreed Martin. I should have chosen a better way to express that the code could be done more succinctly while at the same time pointing out what a more experienced ruby developer would do. Wes First  |  Prev  |