Class: RZoopla::BaseModel
- Inherits:
-
Object
- Object
- RZoopla::BaseModel
- Defined in:
- lib/zoopla/base_model.rb,
lib/rzoopla/base_model.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.attributes ⇒ Object
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BaseModel
constructor
A new instance of BaseModel.
- #to_hash ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BaseModel
Returns a new instance of BaseModel.
3 4 5 6 7 8 9 10 11 |
# File 'lib/zoopla/base_model.rb', line 3 def initialize( = {}) self.class.attributes.each do |attribute| instance_variable_set("@#{attribute}", [attribute]) self.class.send(:define_method, attribute) do instance_variable_get("@#{attribute}") end end end |
Class Attribute Details
.attributes ⇒ Object
Returns the value of attribute attributes.
20 21 22 |
# File 'lib/zoopla/base_model.rb', line 20 def attributes @attributes end |
Instance Method Details
#to_hash ⇒ Object
13 14 15 16 17 |
# File 'lib/zoopla/base_model.rb', line 13 def to_hash Hash[*instance_variables.flat_map { |var| [var.to_s.delete('@'), instance_variable_get(var)] }] end |