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 523 def initialize @atype = {} @short = OptionMap.new @long = OptionCaseMap.new @list = [] end
See OptionParser.accept.
# File optparse.rb, line 533 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
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 601 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. : ((|*pat|)) optional pattern for completion. : (({block})) yielded with the found value when succeeded.
# File optparse.rb, line 640 def complete(id, opt, *pat, &block) __send__(id).complete(opt, *pat, &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 582 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 618 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 655 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