Skip to content

Instantly share code, notes, and snippets.

@mariorcardoso
Last active June 25, 2017 14:23
Show Gist options
  • Save mariorcardoso/e96d24d0bfa8849cdd5d068fa6c95902 to your computer and use it in GitHub Desktop.
Save mariorcardoso/e96d24d0bfa8849cdd5d068fa6c95902 to your computer and use it in GitHub Desktop.
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