Class: Twostroke::Runtime::Types::Number

Inherits:
Primitive show all
Defined in:
lib/twostroke/runtime/types/number.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#has_instance

Constructor Details

#initialize(number) ⇒ Number

Returns a new instance of Number.



4
5
6
# File 'lib/twostroke/runtime/types/number.rb', line 4

def initialize(number)
  @number = number
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



3
4
5
# File 'lib/twostroke/runtime/types/number.rb', line 3

def number
  @number
end

Instance Method Details

#===(other) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/twostroke/runtime/types/number.rb', line 8

def ===(other)
  if number.zero? && other.is_a?(Number) && other.number.zero?
    # in javascript, -0 and 0 are not equal
    # in ruby they are, and the only way to check if a number is -0 is with #to_s
    # please correct me if there's a better way
    number.to_s[0] == other.number.to_s[0]
  else
    other.is_a?(Number) && number == other.number
  end
end

#infinite?Boolean

Returns:



27
28
29
# File 'lib/twostroke/runtime/types/number.rb', line 27

def infinite?
  number.is_a?(Float) && number.infinite?
end

#nan?Boolean

Returns:



24
25
26
# File 'lib/twostroke/runtime/types/number.rb', line 24

def nan?
  number.is_a?(Float) && number.nan?
end

#typeofObject



18
19
20
# File 'lib/twostroke/runtime/types/number.rb', line 18

def typeof
  "number"
end

#zero?Boolean

Returns:



21
22
23
# File 'lib/twostroke/runtime/types/number.rb', line 21

def zero?
  number.zero?
end