Sha256: 82a37be9c633ea9632f56a5d67dec5b2dd6dfe73c89d88c8a1ab667265c3a4a2

Contents?: true

Size: 595 Bytes

Versions: 2

Compression:

Stored size: 595 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Mixture
  module Coerce
    # Handles coercion of the Set class.
    class Set < Base
      type Types::Set

      coerce_to(Types::Object, Itself)
      coerce_to(Types::Boolean, :any?)

      coerce_to(Types::Set) do |value, type|
        member = type.options.fetch(:members).first
        value.map { |e| Coerce.perform(member, e) }.to_set
      end

      coerce_to(Types::Array) do |value, type|
        member = type.options.fetch(:members).first
        value.map { |e| Coerce.perform(member, e) }.to_a
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mixture-0.7.1 lib/mixture/coerce/set.rb
mixture-0.7.0 lib/mixture/coerce/set.rb