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.
D13563098fc07b07400f833c4e6e7169?d=identicon&s=25 Roger Reeks (cogrady2k)
on 2008-10-20 18: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
B14575f0ca69f10938fdd67e7156e0e1?d=identicon&s=25 Craig Demyanovich (Guest)
on 2008-10-20 18: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.