From: Adam Prescott Date: 2011-03-22T22:01:14+09:00 Subject: Re: summing values in a hash? --001636416ddfb3412a049f11d698 Content-Type: text/plain; charset=UTF-8 On Tue, Mar 22, 2011 at 12:57 PM, Jen wrote: > Is there an inbuilt method to sum all values in a hash and return the > result? > > I.E something like puts hash[values].sum > You could try hash.values.inject { |a, b| a + b } Alternatively, you have the shorter form, inject(&:+) or inject(:+) depending on your version of Ruby. 1.8.7 and higher should support all three. --001636416ddfb3412a049f11d698--