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.



157
158
159
160
161
# File 'lib/diva/type.rb', line 157

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

Instance Method Details

#cast(value) ⇒ Object



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

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



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

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