class Numeric

class Numeric

Modify {Numeric#>} and {Numeric#<} and {Numeric#<=>} because +5 < RangeExtd::Infinity::POSITIVE+ raises ArgumentError(!). In other words, +Integer#<+ does not respect +Object#<=>+ but rewrites it.

I do not know if it has been always the case, or some changes have been made in more recent versions of Ruby.

Note that +Float#<+ etc need to be redefined individually, because they seem not to use +Numeric#<+ any more.

To activate these features, explicitly do one of the following

require "range_extd/numeric"
require "range_extd/object"
require "range_extd/load_all"

Public Instance Methods

<(c) click to toggle source

Special case for comparison with a {RangeExtd::Infinity} instance.

# File lib/range_extd/numeric.rb, line 52
def <(c)
  # Default if self is Complex or something not Integer, Rational, Float or alike
  # or the special case INFINITY.
  return less_than_numeric_before_infinity?(c) if !self.class.method_defined?(:>) || ((abs rescue self) == Float::INFINITY)

  if RangeExtd::Infinity.infinity? c
    c.positive?
  else
    less_than_numeric_before_infinity?(c)
  end
end
<=>(c) click to toggle source

Special case for comparison with a {RangeExtd::Infinity} instance.

# File lib/range_extd/numeric.rb, line 26
def <=>(c)
  # Default if the special case INFINITY.
  return compare_than_numeric_before_infinity?(c) if ((abs rescue self) == Float::INFINITY)

  return (-(c.send(__method__, self) || return)) if RangeExtd::Infinity.infinity? c
  compare_than_numeric_before_infinity?(c)
end
>(c) click to toggle source

Special case for comparison with a {RangeExtd::Infinity} instance.

# File lib/range_extd/numeric.rb, line 37
def >(c)
  # Default if self is Complex or something not Integer, Rational, Float or alike
  # or the special case INFINITY.
  return greater_than_numeric_before_infinity?(c) if !self.class.method_defined?(:>) || ((abs rescue self) == Float::INFINITY)

  if RangeExtd::Infinity.infinity? c
    c.negative?
  else
    greater_than_numeric_before_infinity?(c)
  end
end
compare_than_numeric_before_infinity?(c)

Backup of the original {Numeric#<=>}

Alias for: <=>
greater_than_numeric_before_infinity?(c)

Backup of the original {Numeric#>}

Alias for: >
less_than_numeric_before_infinity?(c)

Backup of the original {Numeric#<}

Alias for: <