Sha256: 3e399d287d8a3ac06b37a968230045424d59dcbef68e1abe10ef9fd518f5b801

Contents?: true

Size: 597 Bytes

Versions: 5

Compression:

Stored size: 597 Bytes

Contents

module Monolens
  module Type
    class Array
      include Type::ErrorHandling

      def initialize(item_type)
        @item_type = item_type
      end

      def self.of(item_type)
        Array.new(item_type)
      end

      def dress(instance, registry, &block)
        fail!("Array expected, got #{instance.class}", &block) unless instance.is_a?(::Array)

        instance.map{|item| @item_type.dress(item, registry, &block) }
      end

      def ===(instance)
        instance.is_a?(::Enumerable) && instance.all?{|item|
          @item_type === item
        }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
monolens-0.6.4 lib/monolens/type/array.rb
monolens-0.6.3 lib/monolens/type/array.rb
monolens-0.6.2 lib/monolens/type/array.rb
monolens-0.6.1 lib/monolens/type/array.rb
monolens-0.6.0 lib/monolens/type/array.rb