Class: Date::Infinity
- Inherits:
-
Numeric
- Object
- Numeric
- Date::Infinity
- Includes:
- Comparable
- Defined in:
- lib/date.rb
Overview
:nodoc:
Instance Method Summary collapse
- #+@ ⇒ Object
- #-@ ⇒ Object
- #<=>(other) ⇒ Object
- #abs ⇒ Object
- #coerce(other) ⇒ Object
- #finite? ⇒ Boolean
- #infinite? ⇒ Boolean
-
#initialize(d = 1) ⇒ Infinity
constructor
A new instance of Infinity.
- #nan? ⇒ Boolean
- #to_f ⇒ Object
- #zero? ⇒ Boolean
Constructor Details
#initialize(d = 1) ⇒ Infinity
Returns a new instance of Infinity.
11 |
# File 'lib/date.rb', line 11 def initialize(d=1) @d = d <=> 0 end |
Instance Method Details
#+@ ⇒ Object
25 |
# File 'lib/date.rb', line 25 def +@ () self.class.new(+d) end |
#-@ ⇒ Object
24 |
# File 'lib/date.rb', line 24 def -@ () self.class.new(-d) end |
#<=>(other) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/date.rb', line 27 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
22 |
# File 'lib/date.rb', line 22 def abs() self.class.new end |
#coerce(other) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/date.rb', line 41 def coerce(other) case other when Numeric; return -d, d else super end end |
#finite? ⇒ Boolean
18 |
# File 'lib/date.rb', line 18 def finite? () false end |
#infinite? ⇒ Boolean
19 |
# File 'lib/date.rb', line 19 def infinite? () d.nonzero? end |
#nan? ⇒ Boolean
20 |
# File 'lib/date.rb', line 20 def nan? () d.zero? end |
#to_f ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/date.rb', line 49 def to_f return 0 if @d == 0 if @d > 0 Float::INFINITY else -Float::INFINITY end end |
#zero? ⇒ Boolean
17 |
# File 'lib/date.rb', line 17 def zero? () false end |