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



7
8
9
# File 'opal/stdlib/date.rb', line 7

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

Instance Method Details

#+@Object



39
40
41
# File 'opal/stdlib/date.rb', line 39

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

#-@Object



35
36
37
# File 'opal/stdlib/date.rb', line 35

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

#<=>(other) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'opal/stdlib/date.rb', line 43

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



31
32
33
# File 'opal/stdlib/date.rb', line 31

def abs
  self.class.new
end

#coerce(other) ⇒ Object



59
60
61
62
63
64
65
66
# File 'opal/stdlib/date.rb', line 59

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

#dObject



11
12
13
# File 'opal/stdlib/date.rb', line 11

def d
  @d
end

#finite?Boolean

Returns:



19
20
21
# File 'opal/stdlib/date.rb', line 19

def finite?
  false
end

#infinite?Boolean

Returns:



23
24
25
# File 'opal/stdlib/date.rb', line 23

def infinite?
  d.nonzero?
end

#nan?Boolean

Returns:



27
28
29
# File 'opal/stdlib/date.rb', line 27

def nan?
  d.zero?
end

#to_fObject



68
69
70
71
72
73
74
75
# File 'opal/stdlib/date.rb', line 68

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

#zero?Boolean

Returns:



15
16
17
# File 'opal/stdlib/date.rb', line 15

def zero?
  false
end