# # 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: # # * #rationalize # * #to_a # * #to_c # * #to_h # * #to_r # * #to_s # # Another method provides inspection: # # * #inspect # # Finally, there is this query method: # # * #nil? # class NilClass def !: () -> true # # Returns `false`: # # false & true # => false # false & Object.new # => false # # Argument `object` is evaluated: # # false & raise # Raises RuntimeError. # def &: (untyped obj) -> false # # 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. # def ===: (nil) -> true | (untyped obj) -> bool # # Returns `nil`. # # This method makes it useful to write: # # while gets =~ /re/ # # ... # end # def =~: (untyped obj) -> nil # # Returns `false` if `object` is `nil` or `false`, `true` otherwise: # # nil ^ nil # => false # nil ^ false # => false # nil ^ Object.new # => true # def ^: (false | nil) -> false | (untyped obj) -> bool # # Returns string `'nil'`: # # nil.inspect # => "nil" # def inspect: () -> "nil" # # Returns `true`. For all other objects, method `nil?` returns `false`. # def nil?: () -> true # # Returns zero as a Rational: # # nil.rationalize # => (0/1) # # Argument `eps` is ignored. # def rationalize: (?untyped eps) -> Rational # # Returns an empty Array. # # nil.to_a # => [] # def to_a: () -> [] # # Returns zero as a Complex: # # nil.to_c # => (0+0i) # def to_c: () -> Complex # # Always returns zero. # # nil.to_f #=> 0.0 # def to_f: () -> Float # # Returns an empty Hash. # # nil.to_h #=> {} # def to_h: () -> {} # # Always returns zero. # # nil.to_i #=> 0 # def to_i: () -> 0 # # Returns zero as a Rational: # # nil.to_r # => (0/1) # def to_r: () -> Rational # # Returns an empty String: # # nil.to_s # => "" # def to_s: () -> "" # # Returns `false` if `object` is `nil` or `false`, `true` otherwise: # # nil | nil # => false # nil | false # => false # nil | Object.new # => true # def |: (nil | false) -> false | (untyped obj) -> bool end