From: Kornelius Kalnbach Date: 2009-11-01T22:56:14+09:00 Subject: [ruby-core:26471] Re: New Features for the Array Module 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]