Method: Array#count
- Defined in:
- lib/ruby/jruby_hack.rb
#count(*args) ⇒ Integer
Count the number of elements that satisfy the predicate
215 216 217 218 219 220 221 222 223 |
# File 'lib/ruby/jruby_hack.rb', line 215 def count(*args) if block_given? inject(0){|n, e| yield(e) ? n + 1 : n } elsif args.empty? size else inject(0){|n, e| e == args.first ? n + 1 : n } end end |