Skip to content

Support optional params and options

Compare
Choose a tag to compare
@nepalez nepalez released this 21 Aug 19:06
class User
  extend Dry::Initializer

 param :name, type: Dry::Types['strict.string']
 param :email, type: Dry::Types['strict.string'], default: proc { nil }
 param :phone, type: Dry::Types['strict.string'], optional: true
end

user = User.new "Andrew"

user.name  # => "Andrew"
user.email # => nil (default)
user.phone # => Dry::Types::UNDEFINED (new feature)