From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-07-05T16:03:16+09:00 Subject: Re: Ruby Code Snippet: Array.count On Sat, 05 Jul 2003 16:48:07 +0900, Mauricio Fern�ndez wrote: > On Sat, Jul 05, 2003 at 03:43:00PM +0900, Simon Strandgaard wrote: >> >> I have added your Array#count (using inject), here: >> >> http://www.rubygarden.org/ruby?StandardClassExtensions/Array > > The other version is faster IMHO, and in this case at least as readable: > > class Array > def count > sum = 0 > each { |x| sum += 1 if yield x } > sum > end > end Ok.. I have now added both :-) -- Simon Strandgaard