Created
October 29, 2020 18:04
-
-
Save havenwood/34400e7f028081c36428f14057729187 to your computer and use it in GitHub Desktop.
This file contains 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
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