Last active
June 25, 2017 14:38
-
-
Save mariorcardoso/b8a4aff0cb526218e521269fe9331078 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 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