Class: Typedocs::TypeSpec::Or

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(children) ⇒ Or

Returns a new instance of Or.

Raises:



164
165
166
167
168
169
170
# File 'lib/typedocs/type_spec.rb', line 164

def initialize(children)
  raise ArgumentError, "Children is empty" if children.empty?
  children.each do|c|
    Typedocs.ensure_klass(c, Typedocs::TypeSpec)
  end
  @children = children
end

Instance Method Details

#to_sourceObject



174
175
176
# File 'lib/typedocs/type_spec.rb', line 174

def to_source
  "#{@children.map(&:to_source).join('|')}"
end

#valid?(obj) ⇒ Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/typedocs/type_spec.rb', line 171

def valid?(obj)
  @children.any?{|spec| spec.valid? obj}
end