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