Class: Typedocs::TypeSpec::ArrayAsStruct

Inherits:
Typedocs::TypeSpec show all
Defined in:
lib/typedocs/type_spec.rb

Instance Method Summary collapse

Methods inherited from Typedocs::TypeSpec

#error_message_for

Constructor Details

#initialize(specs) ⇒ ArrayAsStruct

Returns a new instance of ArrayAsStruct.



106
107
108
109
# File 'lib/typedocs/type_spec.rb', line 106

def initialize(specs)
  specs.each {|s| Typedocs.ensure_klass(s, Typedocs::TypeSpec) }
  @specs = specs
end

Instance Method Details

#to_sourceObject



115
116
117
# File 'lib/typedocs/type_spec.rb', line 115

def to_source
  "[#{@specs.map(&:to_source).join(', ')}]"
end

#valid?(obj) ⇒ Boolean

Returns:

  • (Boolean)


110
111
112
113
114
# File 'lib/typedocs/type_spec.rb', line 110

def valid?(obj)
  obj.is_a?(::Array) &&
  @specs.size == obj.size &&
  @specs.zip(obj).all?{|spec,elm| spec.valid?(elm)}
end