Class: Diva::Type::ArrayType

Inherits:
MetaType show all
Defined in:
lib/diva/type.rb

Instance Attribute Summary

Attributes inherited from MetaType

#name

Instance Method Summary collapse

Methods inherited from MetaType

#inspect

Constructor Details

#initialize(type) ⇒ ArrayType

Returns a new instance of ArrayType.



163
164
165
166
167
# File 'lib/diva/type.rb', line 163

def initialize(type)
  type = Diva::Type(type)
  super("#{type.name}_array")
  @type = type
end

Instance Method Details

#cast(value) ⇒ Object



169
170
171
172
# File 'lib/diva/type.rb', line 169

def cast(value)
  raise Diva::InvalidTypeError, "The value is not a `#{name}'." unless value.is_a?(Enumerable)
  value.to_a.map(&@type.method(:cast))
end

#to_sObject



174
175
176
# File 'lib/diva/type.rb', line 174

def to_s
  "Array of #{@type.to_s}"
end