Last active
June 25, 2017 14:23
-
-
Save mariorcardoso/e96d24d0bfa8849cdd5d068fa6c95902 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 Grade | |
include Comparable | |
attr_reader :percentage | |
def initialize(percentage) | |
@percentage = percentage | |
end | |
def better_than?(other) | |
self > other | |
end | |
def worse_than?(other) | |
self < other | |
end | |
def <=>(other) | |
percentage <=> other.percentage | |
end | |
def hash | |
percentage.hash | |
end | |
def to_s | |
if percentage < 20 | |
'poor' | |
elsif percentage < 50 | |
'unsatisfactory' | |
elsif percentage < 70 | |
'satisfactory' | |
elsif percentage < 90 | |
'good' | |
else | |
'excellent' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment