Created
October 26, 2014 09:14
-
-
Save mh-github/8ccde29d1db8df39ff5b to your computer and use it in GitHub Desktop.
Ruby utility module to simulate a Python tuple to be used for sorting
This file contains hidden or 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
| module MH_util | |
| Tuple = Struct.new(:first, :second) do | |
| def <=>(other) | |
| return second <=> other.second if first == other.first | |
| first <=> other.first | |
| end | |
| def to_s | |
| "(#{first}, #{second})" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment