Class

The class of the singleton object nil.

Several of its methods act as operators:

Others act as converters, carrying the concept of nullity to other classes:

Another method provides inspection:

Finally, there is this query method:

Instance Methods

Returns false:

false & true       # => false
false & Object.new # => false

Argument object is evaluated:

false & raise # Raises RuntimeError.

Returns true or false.

Like Object#==, if object is an instance of Object (and not an instance of one of its many subclasses).

This method is commonly overridden by those subclasses, to provide meaningful semantics in case statements.

Returns nil.

This method makes it useful to write:

while gets =~ /re/
  # ...
end

Returns false if object is nil or false, true otherwise:

nil ^ nil        # => false
nil ^ false      # => false
nil ^ Object.new # => true

Returns string 'nil':

nil.inspect # => "nil"

Returns true. For all other objects, method nil? returns false.

Returns zero as a Rational:

nil.rationalize # => (0/1)

Argument eps is ignored.

Returns an empty Array.

nil.to_a # => []

Returns zero as a Complex:

nil.to_c # => (0+0i)

Always returns zero.

nil.to_f   #=> 0.0

Returns an empty Hash.

nil.to_h   #=> {}

Always returns zero.

nil.to_i   #=> 0

Returns zero as a Rational:

nil.to_r # => (0/1)

Returns an empty String:

nil.to_s # => ""

Returns false if object is nil or false, true otherwise:

nil | nil        # => false
nil | false      # => false
nil | Object.new # => true