Created
December 9, 2011 15:59
-
-
Save marcelloma/1452087 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
module Messenger | |
class Person | |
@@people = [] | |
def initialize(attributes={}) | |
@attributes = { :global_id => nil, :name => nil }.merge(attributes) | |
end | |
def self.create!(attributes={}) | |
person = Person.new(attributes) | |
person.save | |
person | |
end | |
def global_id=(v); @attributes[:global_id] = v; end | |
def global_id; @attributes[:global_id]; end | |
def name=(v); @attributes[:name] = v; end | |
def name; @attributes[:name]; end | |
def save | |
@@people << self | |
end | |
def self.find(global_id) | |
@@people.select do |person| | |
person.global_id == global_id | |
end.first | |
end | |
def self.find_by_name(name) | |
@@people.select do |person| | |
person.name == name | |
end | |
end | |
def self.delete_all | |
@@people = [] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment