What returns is the last expression evaluated in the method writed by
Carlos, you don't need to call return, because the method itself will
return 0 or more than 0. Do you understand?


a = [1,2,3,4,]

def mean(a)
  sum = 0
  a.each do |x|
    sum += x
  end

  if a.size > 0
    sum / a.size
  else
    0
  end
end

puts "mean(a) => #{mean(a)}


 You can also still blowing your mid, this method can have less lines,
take a look:


a = [1,2,3,4,]

def mean(a)
  sum = (a.inject(:+) || 0) #: Fixnum
  a.empty? ? 0 : (sum./(a.size)) #: Fixnum
end

puts "mean(a) => #{mean(a)}

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