2018-10-24 11:05:34 -04:00
|
|
|
# School class
|
2018-09-28 23:55:31 -04:00
|
|
|
class School
|
|
|
|
def initialize
|
|
|
|
@roster = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def students(grade)
|
|
|
|
@roster[grade] || []
|
|
|
|
end
|
|
|
|
|
|
|
|
def add(name, grade)
|
2018-10-24 11:05:34 -04:00
|
|
|
@roster[grade] ||= []
|
2018-09-28 23:55:31 -04:00
|
|
|
@roster[grade].push(name).sort!
|
|
|
|
end
|
|
|
|
|
|
|
|
def students_by_grade
|
2018-10-24 11:05:34 -04:00
|
|
|
@roster.sort.map { |key, value| { grade: key, students: value } }
|
2018-09-28 23:55:31 -04:00
|
|
|
end
|
|
|
|
end
|