From: Dave Thomas Date: 2003-07-05T22:57:25+09:00 Subject: Re: Ruby Code Snippet: Array.count Simon Strandgaard wrote: > On Sat, 05 Jul 2003 14:20:35 +0900, Dave Thomas wrote: > >> class Array >> def count >> inject(0) {|sum, e| yield(e) ? sum + 1 : sum } >> end >> end > > > > I have added your Array#count (using inject), here: My code was written in response to the OP's. However, if you're going to save it for posterity, you should really put it under Enumerable. Dave