Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active July 3, 2026 21:23
Show Gist options
  • Select an option

  • Save havenwood/44c5dffe9409c5d5ca8b4d7364309a41 to your computer and use it in GitHub Desktop.

Select an option

Save havenwood/44c5dffe9409c5d5ca8b4d7364309a41 to your computer and use it in GitHub Desktop.
A Rust-like `Reverse` for Ruby
[2, 3, 1].sort_by { Reverse[it] }
#=> 3, 2, 1
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