Skip to content

anonymous /gist:614ccbbe263cd1196203 secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'active_support/concern'
require 'active_support/core_ext/object/acts_like'
module InfiniteComparable
extend ActiveSupport::Concern
included do
class_exec do
alias_method_chain :<=>, :other
end
end
define_method :'<=>_with_other' do |other|
return self.send(:'<=>_without_other', other) if other.class == self.class
conversion = :"to_#{self.class.name.downcase}"
if other.respond_to?(:infinite?) && other.infinite?
-other.infinite?
elsif other.respond_to?(conversion)
self.send(:'<=>_without_other', other.send(conversion))
else
self.send(:'<=>_without_other', other)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.