dry-rb - dry-types08 Dec 2017
Dry::Types.register_class(User) param :user, Types::User
param :user, Types.Instance(User)
array with members of custom type:
param :user, Types::Strict::Array.of(Types.Instance(User))
optional and default values
use optional type (sum type under the hood):
# value can be nil Types::Strict::String.optional # which is syntactic sugar for Types::Strict::Nil | Types::Strict::String
maybe type is kind of advanced version of optional type (
Maybetypes wrap passed values in
# value is 'bar' when input is nil # (final value can't be nil => `default(nil)` is not allowed) Types::Strict::String.default('bar')
Default types are not evaluated on nil. Default values are evaluated only if no value was given.
type = Types::Strict::String.default('hello') type[nil] # => constraint error type # => 'hello'