Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Danger http://6brand.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Count Values in an Array

This modifies the Array class to allow for easy summing
   1  
   2  class Array
   3    def total
   4      t = 0
   5      self.each { |v| t += v }
   6      t
   7    end
   8  end

Use it like this:
   1  
   2  [1,2,2,3].total  # => 8
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS