Common array query methods in Ruby


Method name/sample call        Meaning

a.size (synonym: length)             Number of elements in the array
a.empty?                             True if a is an empty array; false if it has any elements
a.include?(item) True if the array includes items; false otherwise
a.any? {|item| test } True if any item in the array returns true for the block;
false otherwise
a.all? {|item| test } True if every item in the array returns true for the block;
false otherwis

你可能感兴趣的:(Ruby)