From: Glen Holcomb Date: 2007-08-04T02:08:05+09:00 Subject: Re: Beginner with a question. ------=_Part_67955_7878417.1186160886495 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline When you are defining the one variable in the script are you defining it as a string? i.e. var = "3" 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 > -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_67955_7878417.1186160886495--