sum.push(100)
sum.push(",")
sum.push(200)
allsum = sum.split(",")
while i < 2
totalsum = totalsum + allsum[i]
i = i+ 1
end
for this i am getting the error as Array can't be coerced i开发者_如何学JAVAnto Fixnum in ruby on rails can anybody help me on this
sum = [100, ",", 200]
i = 0
totalsum = 0
for i in 0..sum.length-1 do
if sum[i].kind_of? Integer
totalsum = totalsum + sum[i]
end
end
puts totalsum
I am not sure about the Rails way. But is one of the solution using Ruby.
精彩评论