Class: IpagosRubySdk::BaseModel
- Inherits:
-
Object
- Object
- IpagosRubySdk::BaseModel
- Defined in:
- lib/ipagos_ruby_sdk/models/base_model.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ BaseModel
constructor
A new instance of BaseModel.
-
#to_h ⇒ Object
Este método equivale a tu toArray() de PHP.
Constructor Details
#initialize(attributes = {}) ⇒ BaseModel
Returns a new instance of BaseModel.
6 7 8 9 10 |
# File 'lib/ipagos_ruby_sdk/models/base_model.rb', line 6 def initialize(attributes = {}) attributes.each do |key, value| send("#{key}=", value) if respond_to?("#{key}=") end end |
Instance Method Details
#to_h ⇒ Object
Este método equivale a tu toArray() de PHP
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ipagos_ruby_sdk/models/base_model.rb', line 13 def to_h instance_variables.each_with_object({}) do |var, hash| value = instance_variable_get(var) # Limpiamos el '@' del nombre de la variable key = var.to_s.delete("@") # Si el valor es otro modelo, lo convertimos recursivamente hash[key] = value.respond_to?(:to_h) ? value.to_h : value end end |