secret
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.