Forum: Ruby on Rails get total of values in array

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Roger R. (Guest)
on 2008-10-20 20:00
is there an easy way to add all thevalues stored in an array together?

i tried total =  but i dont think thats right?

thanks for any help
Craig D. (Guest)
on 2008-10-20 20:09
(Received via mailing list)
total = @array.inject(0) { |sum, value| sum + value }

The inject method comes from the Enumerable module, which Array
Docs are here:

This topic is locked and can not be replied to.