Class: Pastvu::Model
- Inherits:
-
Object
- Object
- Pastvu::Model
- Defined in:
- lib/pastvu/model.rb
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Model
constructor
A new instance of Model.
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Model
Returns a new instance of Model.
3 4 5 6 7 8 9 |
# File 'lib/pastvu/model.rb', line 3 def initialize(attributes) attributes.each do |key, value| key = snakecase(key) instance_variable_set("@#{key}", value) self.class.send(:attr_accessor, key) end end |
Instance Method Details
#to_hash ⇒ Object
11 12 13 14 15 16 |
# File 'lib/pastvu/model.rb', line 11 def to_hash instance_variables.each_with_object({}) do |var, object| var = var[1..-1] object[camelize(var).to_sym] = method(var).call end end |