Class: Nullz::NullObject

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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *_args, &_block) ⇒ Object



111
112
113
114
# File 'lib/null_object.rb', line 111

def method_missing(method, *_args, &_block)
  return false if method.to_s.index('?')
  NullObject.new unless method == :to_ary
end

Instance Method Details

#!=(value) ⇒ Object



60
61
62
# File 'lib/null_object.rb', line 60

def !=(value)
  !value.nil?
end

#<(_value) ⇒ Object



95
96
97
# File 'lib/null_object.rb', line 95

def <(_value)
  return false
end

#==(value) ⇒ Object



56
57
58
# File 'lib/null_object.rb', line 56

def ==(value)
  value.nil?
end

#>(_value) ⇒ Object



91
92
93
# File 'lib/null_object.rb', line 91

def >(_value)
  return false
end

#coerce(value) ⇒ Object



36
37
38
# File 'lib/null_object.rb', line 36

def coerce(value)
  [NullObject.new, value]
end

#empty?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/null_object.rb', line 99

def empty?
  true
end

#inspectObject



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

def inspect
  nil.inspect
end

#nil?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/null_object.rb', line 103

def nil?
  true
end

#null?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/null_object.rb', line 107

def null?
  true
end

#rationalizeObject



32
33
34
# File 'lib/null_object.rb', line 32

def rationalize
  nil.rationalize
end

#return_null_object(_value) ⇒ Object Also known as: +, -, *, /, |, ^, ~, &, [], <<, >>



40
41
42
# File 'lib/null_object.rb', line 40

def return_null_object(_value)
  NullObject.new
end

#to_bObject Also known as: to_bool



84
85
86
# File 'lib/null_object.rb', line 84

def to_b
  false
end

#to_cObject



80
81
82
# File 'lib/null_object.rb', line 80

def to_c
  nil.to_c
end

#to_fObject



68
69
70
# File 'lib/null_object.rb', line 68

def to_f
  nil.to_f
end

#to_iObject



72
73
74
# File 'lib/null_object.rb', line 72

def to_i
  nil.to_i
end

#to_rObject



64
65
66
# File 'lib/null_object.rb', line 64

def to_r
  nil.to_r
end

#to_sObject Also known as: to_str



76
77
78
# File 'lib/null_object.rb', line 76

def to_s
  nil.to_s
end