From: Todd Benson Date: 2008-08-26T10:14:38+09:00 Subject: Re: adding string and numbers On Mon, Aug 25, 2008 at 7:46 PM, Adam Iggy wrote: > Dana Merrick wrote: >> Adam Iggy wrote: >>> puts 'did you know there are '+name1.length+name2.length+name3.length+ ' >>> letters in your name?' >>> >>> the problem is i get the strings combined, not adding the seperate >>> numbers together. >> >> Try putting parentheses around the addition, like this: >> >> (name1.length+name2.length+name3.length).to_s >> >> -Dana > > > hurray that worked! > > im not quite sure why it worked though? doesnt it need to be integers to > add together? (integer + integer + integer).to_s Inside the parentheses, those are Integer instances being added together, then the to_s turns the sum into a String object so it will cooperate with the surrounding strings. I hope that makes some sense. Sometimes, I don't even know what I'm saying :-) Todd