Class: Twostroke::Runtime::Types::Number
- Defined in:
- lib/twostroke/runtime/types/number.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
- #===(other) ⇒ Object
- #infinite? ⇒ Boolean
-
#initialize(number) ⇒ Number
constructor
A new instance of Number.
- #nan? ⇒ Boolean
- #typeof ⇒ Object
- #zero? ⇒ Boolean
Methods inherited from Value
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
#number ⇒ Object (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
27 28 29 |
# File 'lib/twostroke/runtime/types/number.rb', line 27 def infinite? number.is_a?(Float) && number.infinite? end |
#nan? ⇒ Boolean
24 25 26 |
# File 'lib/twostroke/runtime/types/number.rb', line 24 def nan? number.is_a?(Float) && number.nan? end |
#typeof ⇒ Object
18 19 20 |
# File 'lib/twostroke/runtime/types/number.rb', line 18 def typeof "number" end |
#zero? ⇒ Boolean
21 22 23 |
# File 'lib/twostroke/runtime/types/number.rb', line 21 def zero? number.zero? end |