If I have a hash
{ "name" => "Bob", "age" => 12 }
with a class
class DryUser < Dry::Struct
attribute :name, Types::String
attribute :age, Types::Int
end
The attributes are not being set correctly.
irb(main):172:0> DryUser.new("name" => "Bob", "age" => 12)
=> #<DryUser name=nil age=nil>
irb(main):173:0>
This works with Virtus
class VirtusUser
include Virtus.model
attribute :name, String
attribute :age, Int
end
irb(main):197:0> VirtusUser.new("name" => "Bob", "age" => 12)
=> #<VirtusUser:0x00007f829ea663f0 @name="Bob", @age=12>
How do I make this work with dry-struct? I searched the documentation and found constructor_type :symbolized
, but that didn’t work with dry-struct
.
I know these gems aren’t the same but this feels like a common use case and would appreciate any help you all can offer. Thanks!