Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

31 lines (25 sloc) 0.823 kb
require 'active_support/concern'
module InfiniteComparable
extend ActiveSupport::Concern
included do
alias_method_chain :<=>, :infinity
end
define_method '<=>_with_infinity' do |other|
if other.class == self.class
self.send(:'<=>_without_infinity', other)
# inf <=> inf
elsif other.respond_to?(:infinite?) && other.infinite? && respond_to?(:infinite?) && infinite?
infinite? <=> other.infinite?
# not_inf <=> inf
elsif other.respond_to?(:infinite?) && other.infinite?
-other.infinite?
# inf <=> not_inf
elsif respond_to?(:infinite?) && infinite?
infinite?
else
conversion = :"to_#{self.class.name.downcase}"
other = other.send(conversion) if other.respond_to?(conversion)
self.send(:'<=>_without_infinity', other)
end
end
end
Jump to Line
Something went wrong with that request. Please try again.