Class: NilClass

Inherits:
Object show all
Includes:
Enumerable, Inform::NilClassObjectHelpers, Inform::NilClassSetHelpers
Defined in:
lib/runtime/mixins.rb,
lib/runtime/helpers.rb,
lib/runtime/helpers.rb

Overview

Define some built-in Inform helper methods

Instance Method Summary collapse

Methods included from Inform::NilClassObjectHelpers

#list_together, #object?, #sysobj?

Methods included from Inform::NilClassSetHelpers

#in?

Methods included from Enumerable

#inform

Methods included from Inform::SetHelpers

#in?, #notin?

Instance Method Details

#+(other) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/runtime/mixins.rb', line 66

def +(other)
  case other
  when String then format(JoinedTemplate, str: self.to_s, other: other.to_s)
  when Integer then 0 + other
  when Enumerable then [] + other
  else format(JoinedTemplate, str: self.to_s, other: other.to_s)
  end
end

#-(other) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/runtime/mixins.rb', line 75

def -(other)
  case other
  when String then self.to_s.delete other
  when Integer then 0 - other
  when Enumerable then [] - other
  else self.to_s.delete other
  end
end

#<(other, default = false) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/runtime/mixins.rb', line 100

def <(other, default = false)
  other > 0
#   return default unless other.respond_to? __method__
#   0.send(__method__, other)
rescue StandardError => _e
  default
end

#<=(other, default = false) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/runtime/mixins.rb', line 108

def <=(other, default = false)
  other >= 0
#   return default unless other.respond_to? __method__
#   0.send(__method__, other)
rescue StandardError => _e
  default
end

#>(other, default = false) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/runtime/mixins.rb', line 84

def >(other, default = false)
  other < 0
#   return default unless other.respond_to? __method__
#   0.send(__method__, other)
rescue StandardError => _e
  default
end

#>=(other, default = false) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/runtime/mixins.rb', line 92

def >=(other, default = false)
  other <= 0
#   return default unless other.respond_to? __method__
#   0.send(__method__, other)
rescue StandardError => _e
  default
end

#[](_key) ⇒ Object

Incompatible with RubyUnits::Unit#to_base def *(other)

0 * other
return self unless other.respond_to? __method__
0.send(__method__, other) rescue self

end



135
136
137
# File 'lib/runtime/mixins.rb', line 135

def [](_key)
  self
end

#[]=(_key, _value) ⇒ Object



139
140
141
# File 'lib/runtime/mixins.rb', line 139

def []=(_key, _value)
  self
end

#each(*_args, &_block) ⇒ Object



170
171
172
# File 'lib/runtime/mixins.rb', line 170

def each(*_args, &_block)
  return # Don't do anything, I'm nil
end

#empty?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/runtime/mixins.rb', line 164

def empty?
  true
end

#join(s) ⇒ Object



174
175
176
# File 'lib/runtime/mixins.rb', line 174

def join(s)
  [].join(s)
end

#refreshObject



178
179
180
# File 'lib/runtime/mixins.rb', line 178

def refresh
  self
end

#to_aryObject



143
144
145
# File 'lib/runtime/mixins.rb', line 143

def to_ary
  []
end

#to_fObject



151
152
153
# File 'lib/runtime/mixins.rb', line 151

def to_f
  0.0
end

#to_iObject



147
148
149
# File 'lib/runtime/mixins.rb', line 147

def to_i
  0
end

#to_strObject



155
156
157
# File 'lib/runtime/mixins.rb', line 155

def to_str
  self.to_s
end

#to_symObject Also known as: intern



159
160
161
# File 'lib/runtime/mixins.rb', line 159

def to_sym
  self
end