module Dry

Public Class Methods

Types(*namespaces, default: Types::Undefined, **aliases) click to toggle source

Export registered types as a module with constants

@example no options

module Types
  # imports all types as constants, uses modules for namespaces
  include Dry.Types()
end
# strict types are exported by default
Types::Integer
# => #<Dry::Types[Constrained<Nominal<Integer> rule=[type?(Integer)]>]>
Types::Nominal::Integer
# => #<Dry::Types[Nominal<Integer>]>

@example changing default types

module Types
  include Dry.Types(default: :nominal)
end
Types::Integer
# => #<Dry::Types[Nominal<Integer>]>

@example cherry-picking namespaces

module Types
  include Dry.Types(:strict, :coercible)
end
# cherry-picking discards default types,
# provide the :default option along with the list of
# namespaces if you want the to be exported
Types.constants # => [:Coercible, :Strict]

@example custom names

module Types
  include Dry.Types(coercible: :Kernel)
end
Types::Kernel::Integer
# => #<Dry::Types[Constructor<Nominal<Integer> fn=Kernel.Integer>]>

@param [Array<Symbol>] namespaces List of type namespaces to export @param [Symbol] default Default namespace to export @param [Hash{Symbol => Symbol}] aliases Optional renamings, like strict: :Draconian

@return [Dry::Types::Module]

@see Dry::Types::Module

@api public

# File lib/dry/types.rb, line 253
def self.Types(*namespaces, default: Types::Undefined, **aliases)
  Types::Module.new(Types.container, *namespaces, default: default, **aliases)
end