Class: Date::Infinity
- Includes:
- Comparable
- Defined in:
- opal/stdlib/date.rb
Instance Method Summary collapse
- #+@ ⇒ Object
- #-@ ⇒ Object
- #<=>(other) ⇒ Object
- #abs ⇒ Object
- #coerce(other) ⇒ Object
- #d ⇒ Object
- #finite? ⇒ Boolean
- #infinite? ⇒ Boolean
-
#initialize(d = 1) ⇒ Infinity
constructor
A new instance of Infinity.
- #nan? ⇒ Boolean
- #to_f ⇒ Object
- #zero? ⇒ Boolean
Methods inherited from Numeric
Constructor Details
#initialize(d = 1) ⇒ Infinity
Returns a new instance of Infinity
7 8 9 |
# File 'opal/stdlib/date.rb', line 7 def initialize(d = 1) @d = d <=> 0 end |
Instance Method Details
#+@ ⇒ Object
39 40 41 |
# File 'opal/stdlib/date.rb', line 39 def +@ self.class.new(+d) end |
#-@ ⇒ Object
35 36 37 |
# File 'opal/stdlib/date.rb', line 35 def -@ self.class.new(-d) end |
#<=>(other) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'opal/stdlib/date.rb', line 43 def <=> (other) case other when Infinity; return d <=> other.d when Numeric; return d else begin l, r = other.coerce(self) return l <=> r rescue NoMethodError end end nil end |
#abs ⇒ Object
31 32 33 |
# File 'opal/stdlib/date.rb', line 31 def abs self.class.new end |
#coerce(other) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'opal/stdlib/date.rb', line 59 def coerce(other) case other when Numeric return -d, d else super end end |
#d ⇒ Object
11 12 13 |
# File 'opal/stdlib/date.rb', line 11 def d @d end |
#to_f ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'opal/stdlib/date.rb', line 68 def to_f return 0 if @d == 0 if @d > 0 Float::INFINITY else -Float::INFINITY end end |