count

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

Returns the number of items in enum through enumeration. If an argument is given, the number of items in enum that are equal to item are counted. If a block is given, it 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
doc_ruby_on_rails
2015-04-04 23:29:20
Comments
Leave a Comment

Please login to continue.