Sha256: 4971ba3002aa3b897014c63e27be46fa945a4f87328dba7d5b96f101065334a0

Contents?: true

Size: 526 Bytes

Versions: 9

Compression:

Stored size: 526 Bytes

Contents

# encoding: utf-8

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

      coerce_to(Types::Object, Itself)

      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

9 entries across 9 versions & 1 rubygems

Version Path
mixture-0.5.1 lib/mixture/coerce/set.rb
mixture-0.5.0 lib/mixture/coerce/set.rb
mixture-0.4.0 lib/mixture/coerce/set.rb
mixture-0.3.6 lib/mixture/coerce/set.rb
mixture-0.3.5 lib/mixture/coerce/set.rb
mixture-0.3.4 lib/mixture/coerce/set.rb
mixture-0.3.2 lib/mixture/coerce/set.rb
mixture-0.3.1 lib/mixture/coerce/set.rb
mixture-0.3.0 lib/mixture/coerce/set.rb