count

ary.count â int
ary.count(obj) â int
ary.count { |item| block } â int
Instance Public methods

Returns the number of elements.

If an argument is given, counts the number of elements which equal obj using ===.

If a block is given, counts the number of elements for which the block returns a true value.

ary = [1, 2, 4, 2]
ary.count                  #=> 4
ary.count(2)               #=> 2
ary.count { |x| x%2 == 0 } #=> 3
doc_ruby_on_rails
2015-03-30 16:08:09
Comments
Leave a Comment

Please login to continue.