Created
March 4, 2013 09:41
-
-
Save paneq/5081112 to your computer and use it in GitHub Desktop.
cmp_tuples beautiful code
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
# Compare the attributes for each Tuple | |
# | |
# @param [Tuple] left | |
# @param [Tuple] right | |
# | |
# @return [-1] | |
# returned if the left should be sorted before the right | |
# | |
# @return [0] | |
# returned if the left and right are equal | |
# | |
# @return [1] | |
# returned if the left should be sorted after the right | |
# | |
# @api private | |
def cmp_tuples(left, right) | |
reduce(0) do |cmp, direction| | |
break cmp if cmp.nonzero? | |
direction.call(left, right) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment