Module: JSONModel::Attributes
- Defined in:
- lib/jsonmodel/attributes.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
2 3 4 5 6 |
# File 'lib/jsonmodel/attributes.rb', line 2 def self.included(base) base.extend ClassMethods #TODO raise if the method already exists base.send(:attr_accessor, *base.attribute_names) end |
Instance Method Details
#attributes ⇒ Object
15 16 17 18 19 20 |
# File 'lib/jsonmodel/attributes.rb', line 15 def attributes self.class.attribute_names.inject({}) do |memo,name| memo[name] = send(name) memo end end |
#initialize(attributes = {}) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/jsonmodel/attributes.rb', line 8 def initialize(attributes = {}) attributes.each do |attribute, value| send("#{attribute}=", value) end super end |