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