Skip to content

Instantly share code, notes, and snippets.

@mariorcardoso
Last active June 25, 2017 14:38
Show Gist options
  • Save mariorcardoso/b8a4aff0cb526218e521269fe9331078 to your computer and use it in GitHub Desktop.
Save mariorcardoso/b8a4aff0cb526218e521269fe9331078 to your computer and use it in GitHub Desktop.
class Temperature
include Comparable
attr_reader :degrees
COLD = 20
HOT = 25
def initialize(degrees)
@degrees = degrees
end
def cold?
self < COLD
end
def hot?
self > HOT
end
def <=>(other)
degrees <=> other.degrees
end
def hash
degrees.hash
end
def to_s
"#{degrees} °C"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment