Class: NO::NullObject

Inherits:
Object
  • Object
show all
Defined in:
lib/no.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/no.rb', line 37

def method_missing name, *args
  if nil.respond_to?(name)
    nil.send(name, *args)
  else
    nil
  end
end

Instance Method Details

#==(a) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/no.rb', line 13

def == a
  if a.is_a?(::NO::NullObject)
    super
  else
    nil.== a
  end
end

#^(a) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/no.rb', line 21

def ^ a
  if a.is_a?(::NO::NullObject) # for "NO::NullObject ^ NO::NullObject returns false"
    false
  else
    nil.^ a
  end
end

#|(a) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/no.rb', line 29

def | a
  if a.is_a?(::NO::NullObject) # for "NO::NullObject | NO::NullObject returns false"
    false
  else
    nil.| a
  end
end