Class: Num
Instance Attribute Summary
Attributes inherited from DataType
Instance Method Summary collapse
- #add(other) ⇒ Object
- #as_bool ⇒ Object
- #as_string ⇒ Object
- #div(other) ⇒ Object
- #ge(other) ⇒ Object
- #gt(other) ⇒ Object
-
#initialize(val = nil) ⇒ Num
constructor
A new instance of Num.
- #le(other) ⇒ Object
- #lt(other) ⇒ Object
- #mod(other) ⇒ Object
- #mul(other) ⇒ Object
- #pow(other) ⇒ Object
- #sub(other) ⇒ Object
Constructor Details
#initialize(val = nil) ⇒ Num
Returns a new instance of Num.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/sdx/vm/datatypes.rb', line 222 def initialize(val=nil) if val != nil @internal = val end @fields = { "__as_string" => (NativeFnInternal.new (Proc.new do as_string end)), "__as_code_string" => (NativeFnInternal.new (Proc.new do as_string end)), "__as_bool" => (NativeFnInternal.new (Proc.new do as_bool end)), "__add" => (NativeFnInternal.new (Proc.new do |other| add other[0] end)), "__sub" => (NativeFnInternal.new (Proc.new do |other| sub other[0] end)), "__mul" => (NativeFnInternal.new (Proc.new do |other| mul other[0] end)), "__div" => (NativeFnInternal.new (Proc.new do |other| div other[0] end)), "__mod" => (NativeFnInternal.new (Proc.new do |other| mod other[0] end)), "__pow" => (NativeFnInternal.new (Proc.new do |other| pow other[0] end)), "__lt" => (NativeFnInternal.new (Proc.new do |other| lt other[0] end)), "__gt" => (NativeFnInternal.new (Proc.new do |other| gt other[0] end)), "__le" => (NativeFnInternal.new (Proc.new do |other| le other[0] end)), "__ge" => (NativeFnInternal.new (Proc.new do |other| ge other[0] end)), "__eq" => (NativeFnInternal.new (lambda do |other| Bool.new @internal == other[0].internal end)), "__neq" => (NativeFnInternal.new (lambda do |other| Bool.new @internal != other[0].internal end)) } end |
Instance Method Details
#add(other) ⇒ Object
283 284 285 |
# File 'lib/sdx/vm/datatypes.rb', line 283 def add(other) Num.new @internal + other.internal end |
#as_bool ⇒ Object
279 280 281 |
# File 'lib/sdx/vm/datatypes.rb', line 279 def as_bool Bool.new true end |
#as_string ⇒ Object
275 276 277 |
# File 'lib/sdx/vm/datatypes.rb', line 275 def as_string Str.new @internal.to_s end |
#div(other) ⇒ Object
295 296 297 |
# File 'lib/sdx/vm/datatypes.rb', line 295 def div(other) Num.new @internal / other.internal end |
#ge(other) ⇒ Object
319 320 321 |
# File 'lib/sdx/vm/datatypes.rb', line 319 def ge(other) Bool.new @internal >= other.internal end |
#gt(other) ⇒ Object
311 312 313 |
# File 'lib/sdx/vm/datatypes.rb', line 311 def gt(other) Bool.new @internal > other.internal end |
#le(other) ⇒ Object
315 316 317 |
# File 'lib/sdx/vm/datatypes.rb', line 315 def le(other) Bool.new @internal <= other.internal end |
#lt(other) ⇒ Object
307 308 309 |
# File 'lib/sdx/vm/datatypes.rb', line 307 def lt(other) Bool.new @internal < other.internal end |
#mod(other) ⇒ Object
299 300 301 |
# File 'lib/sdx/vm/datatypes.rb', line 299 def mod(other) Num.new @internal % other.internal end |
#mul(other) ⇒ Object
291 292 293 |
# File 'lib/sdx/vm/datatypes.rb', line 291 def mul(other) Num.new @internal * other.internal end |