Created
October 8, 2013 16:01
-
-
Save scottcreynolds/6887021 to your computer and use it in GitHub Desktop.
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 Student | |
attr_accessor :name, :twitter, :linkedin, :facebook, :website | |
attr_reader :id | |
@@students = [] | |
def initialize | |
if @@students.count == 0 | |
@id = 1 | |
else | |
@id = @@students.max_by { |s| s.id }.id + 1 | |
end | |
@@students << self | |
end | |
def self.reset_all | |
@@students.clear | |
end | |
def self.all | |
@@students | |
end | |
def self.find_by_name(name) | |
@@students.select { |s| s.name == name } | |
end | |
def self.find(id) | |
@@students.select { |s| s.id == id }.first | |
end | |
def self.delete(id) | |
@@students.reject! { |s| s.id == id} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment