Skip to content

Instantly share code, notes, and snippets.

@Olgagr
Created May 26, 2013 08:26
Show Gist options
  • Save Olgagr/5652070 to your computer and use it in GitHub Desktop.
Save Olgagr/5652070 to your computer and use it in GitHub Desktop.
Comparable module in Ruby
#to use this module the class has to mixin it and define <=> method
class Bid
include Comparable
attr_accessor :estimate
def <=>(other_bid)
if self.estimate > other_bid.estimate
1
else if self.estimate < other_bid.estimate
-1
else
0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment