Class: Docopt::OneOrMore

Inherits:
ParentPattern show all
Defined in:
lib/docopt.rb

Instance Attribute Summary

Attributes inherited from ParentPattern

#children

Attributes inherited from Pattern

#children

Instance Method Summary collapse

Methods inherited from ParentPattern

#flat, #initialize, #inspect

Methods inherited from Pattern

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

Constructor Details

This class inherits a constructor from Docopt::ParentPattern

Instance Method Details

#match(left, collected = nil) ⇒ Object



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/docopt.rb', line 303

def match(left, collected=nil)
  if self.children.count != 1
    raise RuntimeError
  end

  collected ||= []
  l = left
  c = collected
  l_ = nil
  matched = true
  times = 0
  while matched
    # could it be that something didn't match but changed l or c?
    matched, l, c = self.children[0].match(l, c)
    times += (matched ? 1 : 0)
    if l_ == l
      break
    end
    l_ = l
  end
  if times >= 1
    return [true, l, c]
  end
  return [false, left, collected]
end