Skip to content

Instantly share code, notes, and snippets.

@mh-github
Created October 26, 2014 09:14
Show Gist options
  • Select an option

  • Save mh-github/8ccde29d1db8df39ff5b to your computer and use it in GitHub Desktop.

Select an option

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
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