Skip to content

Instantly share code, notes, and snippets.

@hirokazumiyaji
Created March 8, 2016 02:10
Show Gist options
  • Save hirokazumiyaji/e847a3c8b7a35b434ab5 to your computer and use it in GitHub Desktop.
Save hirokazumiyaji/e847a3c8b7a35b434ab5 to your computer and use it in GitHub Desktop.
Master Model
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