Class: Axiom::Types::Infinity

Inherits:
BasicObject
Extended by:
Comparable
Defined in:
lib/axiom/types/support/infinity.rb

Overview

Represent an infinite number

Direct Known Subclasses

NegativeInfinity

Class Method Summary collapse

Class Method Details

.<=>(other) ⇒ 0, 1

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test the number against infinity

Parameters:

Returns:

  • (0)

    returned if the other object is infinity

  • (1)

    returned if the other object is something other than infinity



20
21
22
23
24
25
26
# File 'lib/axiom/types/support/infinity.rb', line 20

def self.<=>(other)
  case other
  when ::BigDecimal                       then 1
  when ->(arg) { arg == number }          then 0
  when ::Numeric, inverse.singleton_class then 1
  end
end

.coerce(other) ⇒ Array(Infinity, Infinity)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerce a number into an Infinity class for comparison

Parameters:

  • other (::Numeric)

Returns:



35
36
37
38
39
40
41
42
43
# File 'lib/axiom/types/support/infinity.rb', line 35

def self.coerce(other)
  case other
  when ::BigDecimal then [inverse, self]
  when number       then [self,    self]
  when ::Numeric    then [inverse, self]
  else
    raise ::TypeError, "#{other.class} cannot be coerced"
  end
end

.succClass<Infinity>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the next successive object, which is always self

Returns:



50
51
52
# File 'lib/axiom/types/support/infinity.rb', line 50

def self.succ
  self
end