One way to do it would be to initialise a local variable outside the 
loop:

count = 0

Increment it inside the loop:

a.each { |number| count+=1 if number >= 0 }

And then return the count.

-- 
Posted via http://www.ruby-forum.com/.