Introduction & Usage
dry-initializer
is a simple mixin of class methods params
and options
for instances.
Synopsis
require 'dry-initializer'
class User
extend Dry::Initializer
param :name, proc(&:to_s)
param :role, default: proc { 'customer' }
option :admin, default: proc { false }
option :phone, optional: true
end
user = User.new 'Vladimir', 'admin', admin: true
user.name # => 'Vladimir'
user.role # => 'admin'
user.admin # => true
user.phone # => nil