Skip to content

Instantly share code, notes, and snippets.

@scottcreynolds
Created October 8, 2013 16:01
Show Gist options
  • Save scottcreynolds/6887021 to your computer and use it in GitHub Desktop.
Save scottcreynolds/6887021 to your computer and use it in GitHub Desktop.
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