Class: Dry::Types::Struct
- Inherits:
-
Object
- Object
- Dry::Types::Struct
- Extended by:
- ClassInterface
- Defined in:
- lib/dry/types/struct.rb,
lib/dry/types/struct/class_interface.rb
Direct Known Subclasses
Defined Under Namespace
Modules: ClassInterface
Instance Attribute Summary
Attributes included from ClassInterface
#constructor, #constructor_type, #equalizer
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(attributes) ⇒ Struct
constructor
A new instance of Struct.
- #to_hash ⇒ Object (also: #to_h)
Methods included from ClassInterface
attribute, attributes, default?, default_attributes, inherited, maybe?, new, schema, try, valid?
Methods included from Builder
#constrained, #constrained_type, #constructor, #default, #enum, #maybe, #optional, #safe, #|
Constructor Details
#initialize(attributes) ⇒ Struct
Returns a new instance of Struct.
9 10 11 |
# File 'lib/dry/types/struct.rb', line 9 def initialize(attributes) attributes.each { |key, value| instance_variable_set("@#{key}", value) } end |
Instance Method Details
#[](name) ⇒ Object
13 14 15 |
# File 'lib/dry/types/struct.rb', line 13 def [](name) public_send(name) end |
#to_hash ⇒ Object Also known as: to_h
17 18 19 20 21 |
# File 'lib/dry/types/struct.rb', line 17 def to_hash self.class.schema.keys.each_with_object({}) do |key, result| result[key] = Hashify[self[key]] end end |