Class: DocoptNG::ParentPattern

Inherits:
Pattern
  • Object
show all
Defined in:
lib/docopt_ng/parent_pattern.rb

Direct Known Subclasses

Either, OneOrMore, Optional, Required

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Pattern

#==, #dump, #either, #fix, #fix_identities, #fix_repeating_arguments, #to_str

Constructor Details

#initialize(*children) ⇒ ParentPattern

Returns a new instance of ParentPattern.



7
8
9
# File 'lib/docopt_ng/parent_pattern.rb', line 7

def initialize(*children)
  @children = children
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/docopt_ng/parent_pattern.rb', line 5

def children
  @children
end

Instance Method Details

#flat(*types) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/docopt_ng/parent_pattern.rb', line 16

def flat(*types)
  if types.include?(self.class)
    [self]
  else
    children.map { |c| c.flat(*types) }.flatten
  end
end

#inspectObject



11
12
13
14
# File 'lib/docopt_ng/parent_pattern.rb', line 11

def inspect
  childstr = children.map(&:inspect)
  "#{self.class.name}(#{childstr.join(', ')})"
end