Class: Date::Infinity

Inherits:
Numeric
  • Object
show all
Includes:
Comparable
Defined in:
lib/date.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(d = 1) ⇒ Infinity

Returns a new instance of Infinity.


16
# File 'lib/date.rb', line 16

def initialize(d=1) @d = d <=> 0 end

Instance Method Details

#[email protected]Object


30
# File 'lib/date.rb', line 30

def [email protected]() self.class.new(+d) end

#[email protected]Object


29
# File 'lib/date.rb', line 29

def [email protected]() self.class.new(-d) end

#<=>(other) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/date.rb', line 32

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

#absObject


27
# File 'lib/date.rb', line 27

def abs() self.class.new end

#coerce(other) ⇒ Object


46
47
48
49
50
51
52
# File 'lib/date.rb', line 46

def coerce(other)
  case other
  when Numeric; return -d, d
  else
    super
  end
end

#finite?Boolean

Returns:

  • (Boolean)

23
# File 'lib/date.rb', line 23

def finite?() false end

#infinite?Boolean

Returns:

  • (Boolean)

24
# File 'lib/date.rb', line 24

def infinite?() d.nonzero? end

#nan?Boolean

Returns:

  • (Boolean)

25
# File 'lib/date.rb', line 25

def nan?() d.zero? end

#to_fObject


54
55
56
57
58
59
60
61
# File 'lib/date.rb', line 54

def to_f
  return 0 if @d == 0
  if @d > 0
    Float::INFINITY
  else
    -Float::INFINITY
  end
end

#zero?Boolean

Returns:

  • (Boolean)

22
# File 'lib/date.rb', line 22

def zero?() false end