Hi,
In message "Re: Array#nitems and Object#nil?"
on Tue, 15 Mar 2005 22:58:07 +0900, Florian Gross <flgr / ccan.de> writes:
|On another note: Can we perhaps introduce Enumerable#count which returns
|the number of elements for which the block is true? I know that we can
|do .find_all { ... }.size, but constructing an Array of all elements
|just to get its size seems wasteful.
enum.inject(0){|i,j| j ? i + 1 : i }
No array construction, bit harder to read than #count.
matz.