grade_school.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class School
  VERSION = 1

  def initialize
    @pupils = Hash.new {|hsh, key| hsh[key] = [] }
  end

  def to_h
    @pupils.sort.to_h
  end

  def add(name, grade)
    @pupils[grade] << name
    @pupils[grade].sort!
  end

  def grade(grade)
    @pupils[grade]
  end
end

Comments


You're not logged in right now. Please login via GitHub to comment