Class: Docopt::Argument

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

Direct Known Subclasses

Command

Instance Attribute Summary

Attributes inherited from ChildPattern

#name, #value

Attributes inherited from Pattern

#children

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ChildPattern

#flat, #initialize, #inspect, #match

Methods inherited from Pattern

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

Constructor Details

This class inherits a constructor from Docopt::ChildPattern

Class Method Details

.parse(class_, source) ⇒ Object



209
210
211
212
213
# File 'lib/docopt.rb', line 209

def self.parse(class_, source)
  name = /(<\S*?>)/.match(source)[0]
  value = /\[default: (.*)\]/i.match(source)
  class_.new(name, (value ? value[0] : nil))
end

Instance Method Details

#single_match(left) ⇒ Object



200
201
202
203
204
205
206
207
# File 'lib/docopt.rb', line 200

def single_match(left)
  left.each_with_index do |p, n|
    if p.class == Argument
      return [n, Argument.new(self.name, p.value)]
    end
  end
  return [nil, nil]
end