Module: Dry::Tuple

Includes:
Core::Constants
Defined in:
lib/dry/tuple.rb,
lib/dry/tuple/struct.rb,
lib/dry/tuple/version.rb,
lib/dry/tuple/type_coercer.rb,
lib/dry/tuple/class_decorator.rb,
lib/dry/tuple/class_interface.rb

Overview

The namespace contains mixins for class decoration with tuple type. The interfaces provide a way to use a tuple in constructors to match proper class by input. The behaviour is similar to the one provided by ‘Dry::Struct::ClassInterface` and allows to combine classes into sums but with positional input validation & coercion.

Examples:

Splat input

class Example
  extend Dry::Tuple::ClassInterface
  tuple Types.Tuple(Types::Integer, Types::String)

  def initializer(a1, a2)
    # ...
  end

  def self.new_from_tuple(input)
    new(*input)
  end
end

Defined Under Namespace

Modules: ClassDecorator, ClassInterface, TypeCoercer Classes: Struct

Constant Summary collapse

VERSION =
'0.4.0'

Class Method Summary collapse

Class Method Details

.loaderObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dry/tuple.rb', line 32

def self.loader
  @loader ||=
    ::Zeitwerk::Loader.new.tap do |loader|
      root = ::File.expand_path("..", __dir__)
      loader.tag = "dry-types-tuple"
      loader.inflector = ::Zeitwerk::GemInflector.new("#{root}/dry-types-tuple.rb")
      loader.push_dir root
      loader.ignore \
        "#{root}/dry-types-tuple.rb",
        "#{root}/dry/types",
        "#{root}/dry/tuple/{struct,version}.rb"

      if defined?(Pry)
        loader.log!
        loader.enable_reloading
      end
    end
end