method

empty?

Importance_1
Ruby latest stable (v1_8_7_72) - 1 note - Class: Array
empty?() public

Returns true if self array contains no elements.

   [].empty?   #=> true
Show source
Register or log in to add new notes.
June 25, 2009
2 thanks

Antonym of empty?

The antonym of empty? is Enumerable#any? method:

  [].empty?  #=> true
  [].any?    #=> false

  [1].empty? #=> false
  [1].any?   #=> true

Be cautious however, if your array might contain nil’s or false’s:

  [false, nil].any? #=> false