Class: Monolens::Type::Array

Inherits:
Object
  • Object
show all
Includes:
ErrorHandling
Defined in:
lib/monolens/type/array.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ErrorHandling

#fail!

Constructor Details

#initialize(item_type) ⇒ Array

Returns a new instance of Array.



6
7
8
# File 'lib/monolens/type/array.rb', line 6

def initialize(item_type)
  @item_type = item_type
end

Class Method Details

.of(item_type) ⇒ Object



10
11
12
# File 'lib/monolens/type/array.rb', line 10

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

Instance Method Details

#===(instance) ⇒ Object



20
21
22
23
24
# File 'lib/monolens/type/array.rb', line 20

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

#dress(instance, registry, &block) ⇒ Object



14
15
16
17
18
# File 'lib/monolens/type/array.rb', line 14

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