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.
- A
- C
- E
- G
- N
- P
- R
- S
Attributes
| [R] | atype | Map from acceptable argument types to pattern and converter pairs. |
| [R] | list |
|
| [R] | long | Map from long style option switches to actual switch objects. |
| [R] | short | Map from short style option switches to actual switch objects. |
Class Public methods
new() Link
Just initializes all instance variables.
Instance Public methods
accept(t, pat = /.*/m, &block) Link
See OptionParser.accept.
# File ruby/lib/optparse.rb, line 837 def accept(t, pat = /.*/m, &block) if pat pat.respond_to?(:match) or raise TypeError, "has no `match'", ParseError.filter_backtrace(caller(2)) 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
append(*args) Link
Appends switch at the tail of the list, and associates short, long and negated long options. Arguments are:
switch-
OptionParser::Switchinstance to be inserted. short_opts-
Listof short style options. long_opts-
Listof long style options. nolong_opts-
Listof long style options with “no-” prefix.
append(switch, short_opts, long_opts, nolong_opts)
complete(id, opt, icase = false, *pat, &block) Link
Searches list id for opt and the optional patterns for completion pat. If icase is true, the search is case insensitive. The result is returned or yielded if a block is given. If it isn’t found, nil is returned.
each_option(&block) Link
Iterates over each option, passing the option to the block.
get_candidates(id) Link
prepend(*args) Link
Inserts switch at the head of the list, and associates short, long and negated long options. Arguments are:
switch-
OptionParser::Switchinstance to be inserted. short_opts-
Listof short style options. long_opts-
Listof long style options. nolong_opts-
Listof long style options with “no-” prefix.
prepend(switch, short_opts, long_opts, nolong_opts)
reject(t) Link
See OptionParser.reject.
search(id, key) Link
Searches key in id list. The result is returned or yielded if a block is given. If it isn’t found, nil is returned.
summarize(*args, &block) Link
Creates the summary table, passing each line to the block (without newline). The arguments args are passed along to the summarize method which is called on every option.
# File ruby/lib/optparse.rb, line 943 def summarize(*args, &block) sum = [] list.reverse_each do |opt| if opt.respond_to?(:summarize) # perhaps OptionParser::Switch s = [] opt.summarize(*args) {|l| s << l} sum.concat(s.reverse) elsif !opt or opt.empty? sum << "" elsif opt.respond_to?(:each_line) sum.concat([*opt.each_line].reverse) else sum.concat([*opt.each].reverse) end end sum.reverse_each(&block) end