Created
October 9, 2013 13:01
-
-
Save rosiehoyem/6900891 to your computer and use it in GitHub Desktop.
School domain model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class School | |
attr_accessor :roster, :name, :grade | |
def initialize(name) | |
@name = name | |
@roster = {} | |
end | |
def add_student(student_name, grade) | |
@roster[grade] ||= [] | |
@roster[grade] << student_name | |
end | |
def grade(grade) | |
@roster.select { |g, student_hash| return student_hash if g == grade} | |
end | |
def sort | |
sorted_hash = {} | |
self.roster.sort.each do |grade_array| | |
sorted_hash[grade_array[0]] = grade_array[1].sort | |
end | |
sorted_hash | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment