Sha256: df38dd8c46821439d0ba682bf948194caaaf07417d6704838e0fce138af86fd6
Contents?: true
Size: 843 Bytes
Versions: 2
Compression:
Stored size: 843 Bytes
Contents
# encoding: utf-8 # frozen_string_literal: true module Mixture module Coerce # Handles coercion of the Array class. class Array < Base type Types::Array coerce_to(Types::Object, Itself) coerce_to(Types::Boolean, :any?) coerce_to(Types::Array) do |value, type| member = type.options.fetch(:members).first value.map { |e| Coerce.perform(member, e) } end coerce_to(Types::Set) do |value, type| member = type.options.fetch(:members).first value.map { |e| Coerce.perform(member, e) } end coerce_to(Types::Hash) do |value, type| member = type.options.fetch(:members) ::Hash[value.map do |element| [Coerce.perform(member[0], element[0]), Coerce.perform(member[1], element[1])] end] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mixture-0.7.1 | lib/mixture/coerce/array.rb |
mixture-0.7.0 | lib/mixture/coerce/array.rb |