Class: NilClass

Inherits:
Object show all
Defined in:
lib/range_extd/nil_class.rb

Overview

Adds a couple of methods in NilClass and modifies the behaviour == slightly so that it returns true for nil-equivalent objects if they return true for nil?

In default, it seems the judgement is based on other.__id__. Note that the method eql? (and of course equal?) unchange.

Here is the summary of the changes:

  • #nowhere? is added, which returns false.

  • #class_raw is added, which returns NilClass

  • (nil == RangeExtd::Nowhere::NOWHERE) returns true

To activate these features, explicitly do either of the following

require "range_extd/nil_class"
require "range_extd/load_all"

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Boolean

returns true if other returns true with nil?.

Returns:

  • (Boolean)


37
38
39
# File 'lib/range_extd/nil_class.rb', line 37

def ==(other)
  other.nil?
end

#class_rawClass

Identical to nil.class

Returns:

  • (Class)


28
29
30
# File 'lib/range_extd/nil_class.rb', line 28

def class_raw
  self.class
end

#double_equals?Object

No overwriting.



32
# File 'lib/range_extd/nil_class.rb', line 32

alias_method :double_equals?, :==

#nowhere?Boolean

returns true

Returns:

  • (Boolean)


21
22
23
# File 'lib/range_extd/nil_class.rb', line 21

def nowhere?
  false
end