Kornelius,
Thank you for you suggestions, I'll try and put out another patch that moves
the sum code to enumerable, and scrap the mean function all together. Also,
i'll try to use the Enumerable#inject method to make the function more
generic.

Thanks,
Daniel Cohen

On Sun, Nov 1, 2009 at 9:56 AM, Kornelius Kalnbach <murphy / rubychan.de>wrote:

> Daniel Cohen wrote:
> > A sum function, that sums the elements in an array if they are
> > numbers;
> I use this one a lot; I actually thought it was in 1.9 already!
>
> The ActiveSupport implementation of Array#sum is particularly useful
> because #+ is defined for a lot of classes, like Strings (so #sum works
> like #join) or Arrays (a one-level #flatten).
>
> Your patch limits the method to Floats; this is not Ruby-like, in my
> view, even if it is faster.
>
> > and a mean (or average) function that finds the mean of the
> > elements in the the array using the sum function.
> This one, however, really only applies to numerical objects. I'm not
> sure about such a method being included into standard Ruby, especially
> when it can be added with
>
>  class Array
>    def mean
>      sum / size
>    end
>  end
>
> easily.
>
> So:
> +1 for Array#sum if it is defined as #inject(&:+)
> -1 on type-limited Array#sum and Array#mean
>
> On second thought: Why not implement this as Enumerable#sum?
>
> [murphy]
>
>