From: Guten on
[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
[Note: parts of this message were removed to make it a legal post.]

On Mon, May 31, 2010 at 10:53 PM, Guten <ywzhaifei(a)gmail.com> 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
----- "Josh Cheek" <josh.cheek(a)gmail.com> wrote:

> On Mon, May 31, 2010 at 10:53 PM, Guten <ywzhaifei(a)gmail.com> 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
On Tue, Jun 1, 2010 at 11:35 AM, Wes Bailey <wes(a)verticalresponse.com> 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

----- "Martin DeMello" <martindemello(a)gmail.com> wrote:

> On Tue, Jun 1, 2010 at 11:35 AM, Wes Bailey <wes(a)verticalresponse.com>
> 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