Method: Enumerable#count
- Defined in:
- enum.c
#count ⇒ Integer #count(item) ⇒ Integer #count {|obj| ... } ⇒ Integer
Returns the number of items in enum, where #size is called if it responds to it, otherwise the items are counted through enumeration. If an argument is given, counts the number of items in enum, for which equals to item. If a block is given, counts the number of elements yielding a true value.
ary = [1, 2, 4, 2]
ary.count # => 4
ary.count(2) # => 2
ary.count{|x|x%2==0} # => 3
172 173 174 |
# File 'enum.c', line 172 static VALUE enum_count(argc, argv, obj) int argc; |