Pass A Block To Count
Last updated
Was this helpful?
Last updated
Was this helpful?
Ruby's module comes with the method #count
for determining how many items are in an array or hash.
The #count
method has a trick up its sleeve though. It can take a block with a predicate that returns true
or false
. It essentially acts like #select
returning the count rather than the array subset itself.