You can explicitly add a 'return', if you like to the following code
provided by Carlos:

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

  if a.size > 0
    return(sum / a.size)
  else
    return(0)
  end
end

saji


Saji N Hameed,
ARC-ENV, Center for Advanced Information Science and Technology,
University of Aizu, Tsuruga, Ikki-machi,
Aizuwakamatsu-shi, Fukushima 965-8580,
Japan

Tel: +81242 37-2736
Fax:+81242 37-2760
 email: saji / u-aizu.ac.jp
 url: http://enformtk.u-aizu.ac.jp
 bib: http://www.researcherid.com/rid/B-9188-2009
code: https://github.com/sajinh


On Wed, Dec 18, 2013 at 3:37 AM, Johanna Bettina <lists / ruby-forum.com>wrote:

> Thank you :). But where is the return?I need to return the mean. Our
> Prof said we need a return so we can later test the function. Now when I
> test it in the "terminal" I can see nothing.Like this:
>
> return mean
>
> end
>
> puts "#{mean(a)}"
>
>
>
>
> But where sould I add it?Please could you explain :), would be nice!
>
> --
> Posted via http://www.ruby-forum.com/.
>