Return to Snippet

Revision: 6244
at May 12, 2008 11:12 by lakedenman


Initial Code
#Set up the hours array
hours = [8, 8, 8, 8]

#Run the inject method on the Array
total_hours = hours.inject {|result, element| result + element}

#Output total hours
puts total_hours #=> 32

Initial URL
http://blog.jayfields.com/2008/03/ruby-inject.html

Initial Description

                                

Initial Title
Add Elements In an Array

Initial Tags
array, ruby

Initial Language
Ruby