dry-rb - dry-initializer
09 Dec 2017optional attributes and default values
-
optional attribute
# option can be not specified at all option :foo, Types::Strict::String, optional: true
-
default value
when using
default
key,optional: true
is implied:# equivalent to `Types::Strict::String, optional: true` option :foo, Types::Strict::String, default: proc { nil } option :foo, Types::Strict::String, default: proc { 'bar' }
NOTE: the last example is not equivalent to:
option :foo, Types::Strict::String.default('bar'), optional: true
such usage is incorrect - when option is not specified, it will be
nil
.