Usually, I think, people write sum with inject:
[1,2,3].inject { |s,i| s + i }
Which is presumably why sum doesn't exist. [1,2,3].inject { |s,i| s + i }
Which is presumably why sum doesn't exist.
Why not use the Array.map and pass it a summing block? That way if you've got an array of things other than numbers, you can correctly utilize the strategy pattern to sum them....