Created
March 8, 2016 02:10
-
-
Save hirokazumiyaji/e847a3c8b7a35b434ab5 to your computer and use it in GitHub Desktop.
Master 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 MasterModel | |
@@records = [ | |
] | |
def initialize(params) | |
@attributes = params | |
end | |
def method_missing(name) | |
if @attributes.key?(name) | |
@attributes[name] | |
else | |
super | |
end | |
end | |
def self.find(id) | |
record = @@records.select do |record| | |
record[:id] == id | |
end.first | |
if record.nil? | |
nil | |
else | |
self.new(record) | |
end | |
end | |
def self.all | |
@@records.map do |record| | |
self.new(record) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment