Module: Stannum::Struct
- Defined in:
- lib/stannum/struct.rb
Overview
Abstract class for defining objects with structured attributes.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Object
Initializes the struct with the given attributes.
Methods included from Entities::Constraints
Methods included from Entities::Attributes
apply, #assign_attributes, #attributes, #attributes=, #properties
Methods included from Entities::Properties
#==, #[], #[]=, #assign_properties, #inspect, #properties, #properties=, #to_h
Instance Method Details
#initialize(attributes = {}) ⇒ Object
Initializes the struct with the given attributes.
For each key in the attributes hash, the corresponding writer method will be called with the attribute value. If the hash does not include the key for an attribute, or if the value is nil, the attribute will be set to its default value.
If the attributes hash includes any keys that do not correspond to an attribute, the struct will raise an error.
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/stannum/struct.rb', line 97 def initialize(attributes = {}) unless attributes.is_a?(Hash) raise ArgumentError, 'attributes must be a Hash' end super(**attributes) SleepingKingStudios::Tools::CoreTools.deprecate( 'Stannum::Struct', 'use Stannum::Entity instead' ) end |