Last active
March 2, 2019 17:21
-
-
Save mfifth/46fb313965ab679409dedf1765232e52 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 :grade | |
def initialize(string) | |
@grade = string.downcase | |
end | |
def ==(other_grade) | |
@grade == other_grade.grade | |
end | |
def <=>(other_grade) | |
letter = other_grade.grade.sub(/[-+]/, '') | |
grade = @grade.sub(/[-+]/, '') | |
if grade == letter | |
return 1 if other_grade.grade.include?("+") | |
return -1 if other_grade.grade.include?('-') | |
0 | |
elsif grade < letter | |
-1 | |
elsif grade > letter | |
1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment