class Axiom::Types::Infinity

Represent an infinite number

Public Instance Methods

<=>(other) click to toggle source

Test the number against infinity

@param [Numeric, Infinity] other

@return [0]

returned if the other object is infinity

@return [1]

returned if the other object is something other than infinity

@api private

# File lib/axiom/types/support/infinity.rb, line 24
def <=>(other)
  klass = self.class
  case other
  when BigDecimal                      then 1
  when ->(arg) { arg == klass.number } then 0
  when ::Numeric, klass.inverse        then 1
  end
end
coerce(other) click to toggle source

Coerce a number into an Infinity instance for comparison

@param [::Numeric] other

@return [Array(Infinity, Infinity)]

@api private

# File lib/axiom/types/support/infinity.rb, line 40
def coerce(other)
  case other
  when BigDecimal        then [inverse, self]
  when self.class.number then [self,    self]
  when ::Numeric         then [inverse, self]
  else
    fail TypeError, "#{other.class} cannot be coerced"
  end
end
succ() click to toggle source

Return the next successive object, which is always self

@return [Infinity]

@api private

# File lib/axiom/types/support/infinity.rb, line 55
def succ
  self
end

Private Instance Methods

inverse() click to toggle source

The inverse instance

@return [Infinity]

@api private

# File lib/axiom/types/support/infinity.rb, line 66
def inverse
  self.class.inverse.instance
end