Class: Dry::Types::Printer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/types/tuple.rb

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

Instance Method Summary collapse

Instance Method Details

#visit_tuple(tuple) ⇒ Object

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.



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/dry/types/tuple.rb', line 190

def visit_tuple(tuple)
  options = tuple.options.dup
  size = tuple.fixed_types.size
  size += 1 unless tuple.rest_type.nil?
  types = options.delete(:types_index)

  visit_options(options, tuple.meta) do |opts|
    header = "Tuple<"
    rest = visit(types.default) { "*: #{_1}" } if types.default

    if size.zero?
      yield "#{header}>#{opts}"
    else
      yield header.dup << (
        types.flat_map do |pos, pos_types|
          Kernel.Array(pos_types).map do |pos_type|
            visit(pos_type) { "#{pos}: #{_1}" }
          end
        end << rest
      ).compact.join(", ") << ">#{opts}"
    end
  end
end