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.



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/dry/types/tuple.rb', line 206

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) { |type| "*: #{type}" } if types.default

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