From: Robert Klemme Date: 2008-11-21T15:41:05+09:00 Subject: Re: Syntax question from a newbie to Ruby On 20.11.2008 17:15, Michael Tomer wrote: > Robert Klemme wrote: >> On 18.11.2008 23:56, David Spitzer wrote: >> puts "I think #{number.to_i + 1} may be a better favorite number >> though..." > > I think you can skip the .to_i when the number is inside #{}. No. Whether you can skip to_i solely depends on the type of "number". Btw, you can easily test that (see below). > In other > words, I think it would be valid and a little more readable to say: > > puts "I think #{number + 1} may be a better favorite number though..." irb(main):001:0> "1"+2 TypeError: can't convert Fixnum into String from (irb):1:in `+' from (irb):1 irb(main):002:0> This has nothing to do where the expression appears. IIRC number is a String here so you must convert it to do integer math. Cheers robert