Class: T::ArrayType

Inherits:
Object
  • Object
show all
Defined in:
lib/emery/type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item_type) ⇒ ArrayType

Returns a new instance of ArrayType.



58
59
60
# File 'lib/emery/type.rb', line 58

def initialize(item_type)
  @item_type = item_type
end

Instance Attribute Details

#item_typeObject (readonly)

Returns the value of attribute item_type.



57
58
59
# File 'lib/emery/type.rb', line 57

def item_type
  @item_type
end

Instance Method Details

#==(other) ⇒ Object



71
72
73
# File 'lib/emery/type.rb', line 71

def ==(other)
  T.instance_of?(ArrayType, other) and self.item_type == other.item_type
end

#check(value) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/emery/type.rb', line 64

def check(value)
  T.check_not_nil(self, value)
  if !value.is_a? Array
    raise TypeError.new("Value '#{value.inspect.to_s}' type is #{value.class} - Array is required")
  end
  value.each { |item_value| T.check(item_type, item_value) }
end

#to_sObject



61
62
63
# File 'lib/emery/type.rb', line 61

def to_s
  "Array[#{item_type.to_s}]"
end