Class: NilObject

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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



2
3
4
# File 'lib/nil_object.rb', line 2

def method_missing(*args, &block)
  self
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/nil_object.rb', line 6

def blank?
  true
end

#present?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/nil_object.rb', line 10

def present?
  false
end

#rationalizeObject



34
35
36
# File 'lib/nil_object.rb', line 34

def rationalize
  to_r
end

#to_aObject



42
43
44
# File 'lib/nil_object.rb', line 42

def to_a
  []
end

#to_cObject



38
39
40
# File 'lib/nil_object.rb', line 38

def to_c
  Complex(0)
end

#to_fObject



26
27
28
# File 'lib/nil_object.rb', line 26

def to_f
  0.0
end

#to_iObject



22
23
24
# File 'lib/nil_object.rb', line 22

def to_i
  0
end

#to_rObject



30
31
32
# File 'lib/nil_object.rb', line 30

def to_r
  Rational(0)
end

#to_sObject



14
15
16
# File 'lib/nil_object.rb', line 14

def to_s
  ""
end

#to_strObject



18
19
20
# File 'lib/nil_object.rb', line 18

def to_str
  ""
end