dry-struct
dry-struct copied to clipboard
MissingAttributeError when access optional field with hash syntax
I all :) hope it is the right place to post.
Describe the bug
i tried to access struct attributes using the hash syntax and i found out different behaviour when access optional field in struct using method (struct.field
) and hash (struct[:field]
).
Is this the intended behaviour or a bug?
To Reproduce
class MyStuct < Dry::Struct
transform_keys(&:to_sym)
attribute? :my_attribute, Dry::Types::Integer.optional
end
Expected behavior
s = MyStruct.new
s.my_attribute # nil
s[:my_attribute] # nil
Actual behavior
s = MyStruct.new
s.my_attribute # nil
s[:my_attribute] #MissingAttributeError