Last active
July 3, 2026 21:23
-
-
Save havenwood/44c5dffe9409c5d5ca8b4d7364309a41 to your computer and use it in GitHub Desktop.
A Rust-like `Reverse` for Ruby
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
| [2, 3, 1].sort_by { Reverse[it] } | |
| #=> 3, 2, 1 |
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
| Reverse = Data.define(:value) do | |
| include Comparable | |
| def <=>(other) | |
| return nil unless other.is_a?(Reverse) | |
| other.value <=> value | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment