Created
April 4, 2012 17:39
-
-
Save jfirebaugh/2304164 to your computer and use it in GitHub Desktop.
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
| # Numeric#nonzero? returns self if num is not zero, nil otherwise. | |
| # This behavior is useful when chaining comparisons. | |
| array.sort { |a, b| (a.foo <=> b.foo).nonzero? || (a.bar <=> b.bar) } | |
| # Alternatively, consider #sort_by: | |
| array.sort_by { |e| [e.foo, e.bar] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment