Last active
January 31, 2016 01:33
-
-
Save holdenhinkle/5c31e86c799cd03a5e37 to your computer and use it in GitHub Desktop.
Grade School
This file contains hidden or 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 School | |
attr_accessor :grades | |
def initialize | |
@grades = {} | |
end | |
def to_h | |
grades.map { |grade, name| grades[grade] = name.sort } | |
grades.sort.to_h | |
end | |
def add(name, grade) | |
grades.has_key?(grade) ? self.grades[grade] << name : self.grades[grade] = [name] | |
end | |
def grade(grade) | |
grades[grade].nil? ? [] : grades[grade] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment