Class: Integer

Inherits:
Object show all
Defined in:
lib/range_extd/numeric.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.



149
150
151
152
153
154
155
156
157
158
# File 'lib/range_extd/numeric.rb', line 149

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.



124
125
126
127
128
129
130
# File 'lib/range_extd/numeric.rb', line 124

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.



135
136
137
138
139
140
141
142
143
144
# File 'lib/range_extd/numeric.rb', line 135

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

Backup of the original #<=>



122
# File 'lib/range_extd/numeric.rb', line 122

alias_method :compare_than_integer_before_infinity?, :<=>

#greater_than_integer_before_infinity?Object

Backup of the original #>



133
# File 'lib/range_extd/numeric.rb', line 133

alias_method :greater_than_integer_before_infinity?, :>

#less_than_integer_before_infinity?Object

Backup of the original #<



147
# File 'lib/range_extd/numeric.rb', line 147

alias_method :less_than_integer_before_infinity?, :<