Class: Date::Infinity

Inherits:
Numeric show all
Includes:
Comparable
Defined in:
opal/stdlib/date.rb

Instance Method Summary collapse

Methods inherited from Numeric

#to_json, #to_n

Constructor Details

#initialize(d = 1) ⇒ Infinity

Returns a new instance of Infinity



5
6
7
# File 'opal/stdlib/date.rb', line 5

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

Instance Method Details

#+@Object



37
38
39
# File 'opal/stdlib/date.rb', line 37

def +@
  self.class.new(+d)
end

#-@Object



33
34
35
# File 'opal/stdlib/date.rb', line 33

def -@
  self.class.new(-d)
end

#<=>(other) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'opal/stdlib/date.rb', line 41

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



29
30
31
# File 'opal/stdlib/date.rb', line 29

def abs
  self.class.new
end

#coerce(other) ⇒ Object



55
56
57
58
59
60
61
62
# File 'opal/stdlib/date.rb', line 55

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

#dObject



9
10
11
# File 'opal/stdlib/date.rb', line 9

def d
  @d
end

#finite?Boolean

Returns:



17
18
19
# File 'opal/stdlib/date.rb', line 17

def finite?
  false
end

#infinite?Boolean

Returns:



21
22
23
# File 'opal/stdlib/date.rb', line 21

def infinite?
  d.nonzero?
end

#nan?Boolean

Returns:



25
26
27
# File 'opal/stdlib/date.rb', line 25

def nan?
  d.zero?
end

#to_fObject



64
65
66
67
68
69
70
71
# File 'opal/stdlib/date.rb', line 64

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

#zero?Boolean

Returns:



13
14
15
# File 'opal/stdlib/date.rb', line 13

def zero?
  false
end