Class: CampusIvy::Object
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- CampusIvy::Object
- Defined in:
- lib/campus_ivy/object.rb
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Object
constructor
A new instance of Object.
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Object
Returns a new instance of Object.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/campus_ivy/object.rb', line 7 def initialize(attributes = {}) super( attributes.transform_values do |value| if value.is_a?(Hash) CampusIvy::Object.new(value) elsif value.is_a?(Array) value.map { |v| v.is_a?(Hash) ? CampusIvy::Object.new(v) : v } else value end end ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/campus_ivy/object.rb', line 21 def method_missing(method, *args, &) if encoding_aware? && method.to_s.end_with?('=') super else value = super if value.is_a?(Hash) CampusIvy::Object.new(value) elsif value.is_a?(Array) value.map { |v| v.is_a?(Hash) ? CampusIvy::Object.new(v) : v } else value end end end |