Skip to content
Browse files

Added Enumerable extensions (sum and product).

  • Loading branch information...
1 parent 68b4873 commit 46172430e0858315efb69ca991023d3bda4ac3a8 @jimweirich committed Sep 9, 2009
Showing with 10 additions and 0 deletions.
  1. +10 −0 ext/enumerable.rb
View
10 ext/enumerable.rb
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+
+module Enumerable
+ def sum
+ inject(0) { |r, i| r + i }
+ end
+ def product
+ inject(1) { |r, i| r * i }
+ end
+end

0 comments on commit 4617243

Please sign in to comment.
Something went wrong with that request. Please try again.