From: Jason Roelofs Date: 2007-08-04T02:03:42+09:00 Subject: Re: Beginner with a question. ------=_Part_27602_7275372.1186160626617 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline It seems like you are coming from Perl or PHP where such expressions are converted for you. This is not the case in Ruby. The language may be dynamicly typed, but it's strongly typed, so adding a FixNum to a String doesn't make sense. Thus, you're best off doing the following: favnum = favnum.to_i plus1 = plus1.to_i and continue with actual FixNum objects. Also, make libral use of string replacements: puts "Try #{favnum + plus1} ..." Such a thing calls #to_s on the result of whats in #{...}. Welcome to Ruby! Jason On 8/3/07, clockwork@sigsys.org wrote: > > So I am new to ruby, and I seem to be stuck on a seemingly simple problem. > I > have two variable's, one that is defined in the script, and one that is > grabbed from input. I can add them together just fine, but I have not come > up with a way to put the addition statement inline with strings. For > instance: > > puts favnum.to_i + plus1.to_i > > Works producing the expected result. However when I try something like > this: > > puts 'Try ' + favnum + plus1 + ' has the result.' > > I get errors. I have tried declaring the variables as integers, and tried > various syntax's on that line, but the solution is escaping me and I have > not found a good way to do this. I would also be willing to do a variable > to > define the item I want to add into the line, such as: > > finalnum = favnum.to_i + plus1.to_i > > But that doesnt produce the desired result either as the following doesnt > work: > > puts 'Try '+ finalnum +' instead.' > > In both cases I also tried forcing .to_i but that didnt help. (though > doing > a "puts finalnum" works.) > > So what sort of silly syntactical error am I making ? > > (Apologies if this is the wrong place to post this, it seemed like my best > bet.) > > ~Clockwork > ------=_Part_27602_7275372.1186160626617--