Class: BikeReg::Object
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- BikeReg::Object
- Defined in:
- lib/bike_reg/object.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Object
constructor
A new instance of Object.
- #to_ostruct(obj) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Object
Returns a new instance of Object.
7 8 9 |
# File 'lib/bike_reg/object.rb', line 7 def initialize(attributes) super(to_ostruct(attributes)) end |
Instance Method Details
#to_ostruct(obj) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bike_reg/object.rb', line 11 def to_ostruct(obj) case obj when Hash new_obj = obj.transform_keys { |key| underscore(key) } OpenStruct.new(new_obj.transform_values { |val| to_ostruct(val) }) when Array obj.map { |o| to_ostruct(o) } else # Assumed to be a primitive value obj end end |