Class: Fukubukuro::ECMA::Core::Number

Inherits:
Container show all
Defined in:
lib/amber/fukubukuro/ecma_core.rb

Instance Attribute Summary

Attributes inherited from Container

#original, #value

Instance Method Summary collapse

Methods inherited from Container

bind_to_original, #inspect, inspect, #method_missing, #pretty_print

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Fukubukuro::ECMA::Core::Container

Instance Method Details

#*(other) ⇒ Object



192
193
194
195
196
197
198
199
# File 'lib/amber/fukubukuro/ecma_core.rb', line 192

def * other
  case other
  when Number
    Number.new value * other.value
  else
    raise ::ArgumentError, 'expected Number, got %p' % [other]
  end
end

#+(other) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/amber/fukubukuro/ecma_core.rb', line 81

def + other
  case other
  when Number
    Number.new value + other.value
  when String
    String.new value.to_s + other.value
  else
    raise ::ArgumentError, 'expected Number, got %p' % [other]
  end
end

#+@Object



187
188
189
190
# File 'lib/amber/fukubukuro/ecma_core.rb', line 187

def +@
  # Number.new(+value)
  self
end

#-(other) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/amber/fukubukuro/ecma_core.rb', line 92

def - other
  case other
  when Number
    Number.new value - other.value
  else
    raise ::ArgumentError, 'expected Number, got %p' % [other]
  end
end

#-@Object



183
184
185
# File 'lib/amber/fukubukuro/ecma_core.rb', line 183

def -@
  Number.new(-value)
end

#/(other) ⇒ Object



201
202
203
204
205
206
207
208
# File 'lib/amber/fukubukuro/ecma_core.rb', line 201

def / other
  case other
  when Number
    Number.new value.to_f / other.value
  else
    raise ::ArgumentError, 'expected Number, got %p' % [other]
  end
end

#<(other) ⇒ Object



141
142
143
144
145
146
147
148
# File 'lib/amber/fukubukuro/ecma_core.rb', line 141

def < other
  case other
  when Number
    value < other.value
  else
    raise ::ArgumentError, 'expected Number, got %p' % [other]
  end
end

#<<(other) ⇒ Object



210
211
212
213
214
215
216
217
# File 'lib/amber/fukubukuro/ecma_core.rb', line 210

def << other
  case other
  when Number
    Number.new value << other.value
  else
    raise ::ArgumentError, 'expected Number, got %p' % [other]
  end
end

#<=(other) ⇒ Object



150
151
152
153
154
155
156
157
# File 'lib/amber/fukubukuro/ecma_core.rb', line 150

def <= other
  case other
  when Number
    value <= other.value
  else
    raise ::ArgumentError, 'expected Number, got %p' % [other]
  end
end

#==(other) ⇒ Object



159
160
161
162
163
164
165
166
# File 'lib/amber/fukubukuro/ecma_core.rb', line 159

def == other
  case other
  when Number
    value == other.value
  else
    false
  end
end

#_decrement_prefixObject



111
112
113
114
# File 'lib/amber/fukubukuro/ecma_core.rb', line 111

def _decrement_prefix
  self.value -= 1
  self
end

#_decrement_suffixObject



116
117
118
119
# File 'lib/amber/fukubukuro/ecma_core.rb', line 116

def _decrement_suffix
  self.value -= 1
  Number.new value + 1
end

#_increment_prefixObject



101
102
103
104
# File 'lib/amber/fukubukuro/ecma_core.rb', line 101

def _increment_prefix
  self.value += 1
  self
end

#_increment_suffixObject



106
107
108
109
# File 'lib/amber/fukubukuro/ecma_core.rb', line 106

def _increment_suffix
  self.value += 1
  Number.new value - 1
end

#decrement(by) ⇒ Object



131
132
133
134
# File 'lib/amber/fukubukuro/ecma_core.rb', line 131

def decrement by
  self.value -= by.value
  self
end

#decrement_const(by) ⇒ Object



136
137
138
139
# File 'lib/amber/fukubukuro/ecma_core.rb', line 136

def decrement_const by
  self.value -= by
  self
end

#false?Boolean

Returns:



228
229
230
# File 'lib/amber/fukubukuro/ecma_core.rb', line 228

def false?
  value.zero?
end

#increment(by) ⇒ Object



121
122
123
124
# File 'lib/amber/fukubukuro/ecma_core.rb', line 121

def increment by
  self.value += by.value
  self
end

#increment_const(by) ⇒ Object



126
127
128
129
# File 'lib/amber/fukubukuro/ecma_core.rb', line 126

def increment_const by
  self.value += by
  self
end

#lsr(other) ⇒ Object



219
220
221
222
223
224
225
226
# File 'lib/amber/fukubukuro/ecma_core.rb', line 219

def lsr other
  case other
  when Number
    Number.new value.lsr(other.value)
  else
    raise ::ArgumentError, 'expected Number, got %p' % [other]
  end
end

#not_equal_const(other) ⇒ Object



179
180
181
# File 'lib/amber/fukubukuro/ecma_core.rb', line 179

def not_equal_const other
  value != other
end

#true?Boolean

Returns:



231
232
233
# File 'lib/amber/fukubukuro/ecma_core.rb', line 231

def true?
  value.nonzero?
end

#value_inspectObject



72
73
74
75
76
77
78
79
# File 'lib/amber/fukubukuro/ecma_core.rb', line 72

def value_inspect
  case value
  when ::Integer
    value.to_s
  when ::Float
    ('%0.0f' % value).chomp('.0')
  end
end