Class: SimpleStruct
- Inherits:
-
Object
- Object
- SimpleStruct
- Defined in:
- lib/bottlerocket/simple_struct.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ SimpleStruct
constructor
A new instance of SimpleStruct.
- #method_missing(field, *args) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ SimpleStruct
Returns a new instance of SimpleStruct.
4 5 6 |
# File 'lib/bottlerocket/simple_struct.rb', line 4 def initialize(attributes={}) self.attributes = attributes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(field, *args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bottlerocket/simple_struct.rb', line 12 def method_missing(field, *args) begin if field.to_s.end_with?('=') field_name = field.to_s.sub '=', '' @attributes[field_name] = args.first else @attributes[field] end rescue super(field, *args) end end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
2 3 4 |
# File 'lib/bottlerocket/simple_struct.rb', line 2 def attributes @attributes end |