From: 7stud -- Date: 2009-08-29T06:24:25+09:00 Subject: Re: Error with an array of strings Tim Hunter wrote: > Tom Smith wrote: >> until $_ == "n" >> >> >> Needless to say, I'm getting an error with the averageall, since (I >> assume) it's trying to divide by strings. I figure I need to convert the >> array of strings to an array of integers. Alas, I can't seem to track >> down the correct solution. Any help would be much appreciated for this >> newbie to Ruby. >> >> Thanks. > > The to_i method converts a string to an integer, assuming the string > really can be so converted. > > "1".to_i => 1 > > ["1", "2", "3"].map {|d| d.to_i} => [1, 2, 3] No. total.push(number.to_i) The op's atrocious choice of variable names is coming back to haunt him. The op is treating total as if it is an Integer. However, total is an array. Just because you call something a dog doesn't mean it isn't a pig. That reminds me of the question: How many legs does a dog have if you call its tail a leg? A: Four. Just because you call a dog's tail a leg doesn't mean it's a leg. -- Posted via http://www.ruby-forum.com/.