ruby - grade-school
This commit is contained in:
parent
da10e318e4
commit
ddf33000c8
@ -1,3 +1,4 @@
|
||||
# School class
|
||||
class School
|
||||
def initialize
|
||||
@roster = {}
|
||||
@ -8,13 +9,11 @@ class School
|
||||
end
|
||||
|
||||
def add(name, grade)
|
||||
if @roster[grade].nil?
|
||||
@roster[grade] = []
|
||||
end
|
||||
@roster[grade] ||= []
|
||||
@roster[grade].push(name).sort!
|
||||
end
|
||||
|
||||
def students_by_grade
|
||||
@roster.sort.map {|key, value| {grade: key, students: value}}
|
||||
@roster.sort.map { |key, value| { grade: key, students: value } }
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user