| Class | List |
| In: |
optparse.rb
|
| Parent: | Object |
Simple option list providing mapping from short and/or long option string to ((<OptionParser::Switch>)), and mapping from acceptable argument to matching pattern and converter pair. Also provides summary feature.
| atype | [R] | Map from acceptable argument types to pattern and converter pairs. |
| list | [R] | List of all switches and summary string. |
| long | [R] | Map from long style option switches to actual switch objects. |
| short | [R] | Map from short style option switches to actual switch objects. |
Just initializes all instance variables.
# File optparse.rb, line 526 def initialize @atype = {} @short = OptionMap.new @long = OptionMap.new @list = [] end
See OptionParser.accept.
# File optparse.rb, line 536 def accept(t, pat = /.*/, &block) if pat pat.respond_to?(:match) or raise TypeError, "has no `match'" else pat = t if t.respond_to?(:match) end unless block block = pat.method(:convert).to_proc if pat.respond_to?(:convert) end @atype[t] = [pat, block] end
# File optparse.rb, line 681 def add_banner(to) list.each do |opt| if opt.respond_to?(:add_banner) opt.add_banner(to) end end to end
OptionParser::List#append(switch, short_opts, long_opts, nolong_opts)
Appends ((|switch|)) at tail of the list, and associates short, long and negated long options.
:Parameters:
: ((|switch|))
((<OptionParser::Switch>)) instance to be inserted.
: ((|short_opts|))
list of short style options.
: ((|long_opts|))
list of long style options.
: ((|nolong_opts|))
list of long style options with (({"no-"})) prefix.
# File optparse.rb, line 604 def append(*args) update(*args) @list.push(args[0]) end
OptionParser::List#complete(id, opt, *pat, &block)
Searches list ((|id|)) for ((|opt|)) and ((|*pat|)).
:Parameters:
: ((|id|))
searching list.
: ((|opt|))
searching key.
: ((|icase|))
search case insensitive if true.
: ((|*pat|))
optional pattern for completion.
: (({block}))
yielded with the found value when succeeded.
# File optparse.rb, line 645 def complete(id, opt, icase = false, *pat, &block) __send__(id).complete(opt, icase, *pat, &block) end
OptionParser::List#each_option
Iterates for each options.
# File optparse.rb, line 654 def each_option(&block) list.each(&block) end
OptionParser::List#prepend(switch, short_opts, long_opts, nolong_opts)
Inserts ((|switch|)) at head of the list, and associates short, long and negated long options.
# File optparse.rb, line 585 def prepend(*args) update(*args) @list.unshift(args[0]) end
OptionParser::List#search(id, key) [{block}]
Searches ((|key|)) in ((|id|)) list.
:Parameters:
: ((|id|))
searching list.
: ((|k|))
searching key.
: (({block}))
yielded with the found value when succeeded.
# File optparse.rb, line 621 def search(id, key) if list = __send__(id) val = list.fetch(key) {return nil} return val unless block_given? yield(val) end end
OptionParser::List#summarize(*args) {…}
Making summary table, yields the (({block})) with each lines. Each elements of (({@list})) should be able to (({summarize})).
:Parameters:
: ((|args|))
passed to elements#summarize through.
: (({block}))
to be passed each lines(without newline).
# File optparse.rb, line 669 def summarize(*args, &block) list.each do |opt| if opt.respond_to?(:summarize) # perhaps OptionParser::Switch opt.summarize(*args, &block) elsif opt.empty? yield("") else opt.each(&block) end end end