Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created October 29, 2020 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/34400e7f028081c36428f14057729187 to your computer and use it in GitHub Desktop.
Save havenwood/34400e7f028081c36428f14057729187 to your computer and use it in GitHub Desktop.
class GrossWeight
include Comparable
attr_reader :value
def initialize(value)
@value = value
end
def <=>(other)
value <=> other.value
end
def succ
self.class.new(value.succ)
end
end
low = (...GrossWeight.new(40))
medium = (GrossWeight.new(40)..GrossWeight.new(50))
case GrossWeight.new(42)
in ^low
:low
in ^medium
:medium
else
:high
end
#=> :medium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment