Skip to content

Instantly share code, notes, and snippets.

@mkweick
Last active February 20, 2016 15:39
Show Gist options
  • Select an option

  • Save mkweick/21e871501ed46980137f to your computer and use it in GitHub Desktop.

Select an option

Save mkweick/21e871501ed46980137f to your computer and use it in GitHub Desktop.
Grade School
class School
def initialize
@school = Hash.new { |school, grade| school[grade] = [] }
end
def to_h
@school.sort.map { |grade, students| [grade, students.sort] }.to_h
end
def add(student, grade)
@school[grade] << student
end
def grade(grade)
@school[grade]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment