Class: Date::Infinity
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.
19 |
# File 'ext/date/lib/date.rb', line 19 def initialize(d=1) @d = d <=> 0 end |
Instance Method Details
#+@ ⇒ Object
33 |
# File 'ext/date/lib/date.rb', line 33 def +@() self.class.new(+d) end |
#-@ ⇒ Object
32 |
# File 'ext/date/lib/date.rb', line 32 def -@() self.class.new(-d) end |
#<=>(other) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'ext/date/lib/date.rb', line 35 def <=>(other) case other when Infinity; return d <=> other.d when Float::INFINITY; return d <=> 1 when -Float::INFINITY; return d <=> -1 when Numeric; return d else begin l, r = other.coerce(self) return l <=> r rescue NoMethodError end end nil end |
#abs ⇒ Object
30 |
# File 'ext/date/lib/date.rb', line 30 def abs() self.class.new end |
#coerce(other) ⇒ Object
51 52 53 54 55 56 57 |
# File 'ext/date/lib/date.rb', line 51 def coerce(other) case other when Numeric; return -d, d else super end end |
#finite? ⇒ Boolean
26 |
# File 'ext/date/lib/date.rb', line 26 def finite?() false end |
#infinite? ⇒ Boolean
27 |
# File 'ext/date/lib/date.rb', line 27 def infinite?() d.nonzero? end |
#nan? ⇒ Boolean
28 |
# File 'ext/date/lib/date.rb', line 28 def nan?() d.zero? end |
#to_f ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'ext/date/lib/date.rb', line 59 def to_f return 0 if @d == 0 if @d > 0 Float::INFINITY else -Float::INFINITY end end |
#zero? ⇒ Boolean
25 |
# File 'ext/date/lib/date.rb', line 25 def zero?() false end |