The method should be: array .sum The article is correct .sum shouldn't be on an array, but sum shouldn't be global either. This is why generics exist.
Or you can have a sum method that accepts a block/lambda/anonymous function as an argument. This is done in Smalltalk with detectSum. people detectSum: [ :person | person age ]. items detectSum: [ :item | item price ].
class Array
def detectSum(&block)
self.map(&block).sum
end
end
>> [1, 2, 3].detectSum {|i| i**2}
=> 14
Most Ruby people though would just call #map and #sum in succession on an ad hoc basis.