Skip to content

Instantly share code, notes, and snippets.

@paneq
Created March 4, 2013 09:41
Show Gist options
  • Save paneq/5081112 to your computer and use it in GitHub Desktop.
Save paneq/5081112 to your computer and use it in GitHub Desktop.
cmp_tuples beautiful code
# 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