Class: Axiom::Types::Infinity
- Inherits:
-
Object
- Object
- Axiom::Types::Infinity
- Extended by:
- Options, DescendantsTracker
- Includes:
- Comparable, Singleton
- Defined in:
- lib/axiom/types/support/infinity.rb
Overview
Represent an infinite number
Direct Known Subclasses
Instance Method Summary collapse
-
#<=>(other) ⇒ 0, 1
private
Test the number against infinity.
-
#coerce(other) ⇒ Array(Infinity, Infinity)
private
Coerce a number into an Infinity instance for comparison.
-
#succ ⇒ Infinity
private
Return the next successive object, which is always self.
Methods included from 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
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
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 |
#succ ⇒ 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
56 57 58 |
# File 'lib/axiom/types/support/infinity.rb', line 56 def succ self end |