Class: Integer

Inherits:
Object show all
Defined in:
lib/range_extd/infinity/infinity.rb

Overview

class Integer

The same as Numeric#> and Numeric#<. See them for the background.

Instance Method Summary collapse

Instance Method Details

#<(c) ⇒ Object

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



589
590
591
592
593
594
595
596
597
598
# File 'lib/range_extd/infinity/infinity.rb', line 589

def <(c)
  # Default if self is not comparable (in case the Integer method is redifined by a user).
  return less_than_integer_before_infinity?(c) if !self.class.method_defined?(:>)

  if RangeExtd::Infinity.infinity? c
    c.positive?
  else
    less_than_integer_before_infinity?(c)
  end
end

#<=>(c) ⇒ Object

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



566
567
568
569
570
571
572
# File 'lib/range_extd/infinity/infinity.rb', line 566

def <=>(c)
  # Default if the special case INFINITY (never happens in Default, but a user may define Integer::INFINITY).
  return compare_than_integer_before_infinity?(c) if ((abs rescue self) == Float::INFINITY)

  return (-(c.send(__method__, self) || return)) if RangeExtd::Infinity.infinity? c
  compare_than_integer_before_infinity?(c)
end

#>(c) ⇒ Object

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



576
577
578
579
580
581
582
583
584
585
# File 'lib/range_extd/infinity/infinity.rb', line 576

def >(c)
  # Default if self is not comparable (in case the Integer method is redifined by a user).
  return greater_than_integer_before_infinity?(c) if !self.class.method_defined?(:>)

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

#compare_than_integer_before_infinity?Object

No overwriting.



564
# File 'lib/range_extd/infinity/infinity.rb', line 564

alias_method :compare_than_integer_before_infinity?, :<=>

#greater_than_integer_before_infinity?Object

No overwriting.



574
# File 'lib/range_extd/infinity/infinity.rb', line 574

alias_method :greater_than_integer_before_infinity?, :>

#less_than_integer_before_infinity?Object

No overwriting.



587
# File 'lib/range_extd/infinity/infinity.rb', line 587

alias_method :less_than_integer_before_infinity?, :<