I'm using dry-rb
and dry-struct
. And I wanted make some attributes optional, but I was confused with optional
.
So the thing is, you can't use optional
for skipping attributes. Optional means you can pass nil values, that's all.
So if you want to skip attributes, use this attribute by calling attribute?
class User < Dry::Struct
attribute :name, Types::String
attribute? :age, Types::Integer
end
user = User.new(name: 'Jane')
# => #<User name="Jane" age=nil>
user.age
# => nil