Created
May 26, 2013 08:26
-
-
Save Olgagr/5652070 to your computer and use it in GitHub Desktop.
Comparable module in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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