Module: NullAndVoid::Convertible

Defined in:
lib/null_and_void/convertible.rb

Instance Method Summary collapse

Instance Method Details

#rationalize(*_args) ⇒ Object



19
20
21
# File 'lib/null_and_void/convertible.rb', line 19

def rationalize(*_args)
  Rational(0)
end

#to_aObject Also known as: to_ary



27
28
29
# File 'lib/null_and_void/convertible.rb', line 27

def to_a
  []
end

#to_cObject



9
10
11
# File 'lib/null_and_void/convertible.rb', line 9

def to_c
  Complex(0)
end

#to_fObject



15
16
17
# File 'lib/null_and_void/convertible.rb', line 15

def to_f
  0.0
end

#to_hashObject



33
34
35
# File 'lib/null_and_void/convertible.rb', line 33

def to_hash
  {}
end

#to_htmlObject



37
38
39
# File 'lib/null_and_void/convertible.rb', line 37

def to_html
  ''
end

#to_iObject Also known as: to_int



5
6
7
# File 'lib/null_and_void/convertible.rb', line 5

def to_i
  0
end

#to_jsonObject



41
42
43
# File 'lib/null_and_void/convertible.rb', line 41

def to_json(*)
  'null'
end

#to_modelObject

rubocop:disable Style/ExtraSpacing



54
55
56
57
58
59
60
61
# File 'lib/null_and_void/convertible.rb', line 54

def to_model
  base_path         = NullAndVoid::Inflections.demodulize(self.class.name)
  module_path       = NullAndVoid::Inflections.deconstantize(self.class.name)
  source_model      = base_path.gsub(/^Null/, '')
  source_model_path = "#{module_path}::#{source_model}"

  NullAndVoid::Inflections.constantize(source_model_path).new
end

#to_rObject



23
24
25
# File 'lib/null_and_void/convertible.rb', line 23

def to_r
  Rational(0)
end

#to_sObject



49
50
51
# File 'lib/null_and_void/convertible.rb', line 49

def to_s
  ''
end

#to_xmlObject



45
46
47
# File 'lib/null_and_void/convertible.rb', line 45

def to_xml
  ''
end