Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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