Created
October 13, 2013 18:09
-
-
Save irmiller22/6965392 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
| require 'pry' | |
| class School | |
| attr_accessor :roster, :school | |
| @@schools = [] | |
| def initialize(school) | |
| @school = school | |
| @roster = {} | |
| @@schools << self | |
| end | |
| def add_student(name, grade) | |
| self.roster[grade] ||= [] | |
| self.roster[grade] << name | |
| end | |
| def grade(grade) | |
| self.roster[grade] | |
| end | |
| def sort | |
| hash_roster = Hash[self.roster.sort_by {|grade, students| grade}] | |
| hash_roster.keys.each do |grade, students| | |
| hash_roster[grade] = hash_roster[grade].sort | |
| end | |
| #had issues trying to get it not to return an array, | |
| # so i used a roundabout sorting statement | |
| hash_roster | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment