Class: Axiom::Types::Infinity

Inherits:
Object
  • Object
show all
Extended by:
Options, DescendantsTracker
Includes:
Comparable, Singleton
Defined in:
lib/axiom/types/support/infinity.rb

Overview

Represent an infinite number

Direct Known Subclasses

NegativeInfinity

Instance Method Summary collapse

Methods included from Options

accept_options

Instance 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



25
26
27
28
29
30
31
32
# File 'lib/axiom/types/support/infinity.rb', line 25

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) ⇒ 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 instance for comparison

Parameters:

  • other (::Numeric)

Returns:



41
42
43
44
45
46
47
48
49
# File 'lib/axiom/types/support/infinity.rb', line 41

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

#succInfinity

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:



56
57
58
# File 'lib/axiom/types/support/infinity.rb', line 56

def succ
  self
end