Class: Devbootcamp::Model
- Inherits:
-
Object
- Object
- Devbootcamp::Model
- Defined in:
- lib/devbootcamp/model.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
-
#initialize(attributes = {}) ⇒ Model
constructor
A new instance of Model.
- #serializable_hash(options = nil) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Model
Returns a new instance of Model.
14 15 16 |
# File 'lib/devbootcamp/model.rb', line 14 def initialize(attributes={}) @attributes = attributes.with_indifferent_access end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
18 19 20 |
# File 'lib/devbootcamp/model.rb', line 18 def attributes @attributes end |
Class Method Details
.attributes(*attributes) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/devbootcamp/model.rb', line 4 def self.attributes *attributes @attributes ||= [] if !attributes.empty? @attributes += attributes.map(&:to_sym).each do |attribute| define_method(attribute){ @attributes[attribute] } end end @attributes end |
Instance Method Details
#as_json(options = nil) ⇒ Object
24 25 26 |
# File 'lib/devbootcamp/model.rb', line 24 def as_json(=nil) attributes end |
#serializable_hash(options = nil) ⇒ Object
20 21 22 |
# File 'lib/devbootcamp/model.rb', line 20 def serializable_hash(=nil) attributes end |