| 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 520 def initialize @atype = {} @short = OptionMap.new @long = OptionMap.new @list = [] end
See OptionParser.accept.
# File optparse.rb, line 530 def accept(t, pat = /.*/nm, &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
Appends switch at the tail of the list, and associates short, long and negated long options. Arguments are:
| 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. |
append(switch, short_opts, long_opts, nolong_opts)
# File optparse.rb, line 594 def append(*args) update(*args) @list.push(args[0]) end
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.
# File optparse.rb, line 616 def complete(id, opt, icase = false, *pat, &block) __send__(id).complete(opt, icase, *pat, &block) end
Iterates over each option, passing the option to the block.
# File optparse.rb, line 623 def each_option(&block) list.each(&block) end
Inserts switch at the head of the list, and associates short, long and negated long options. Arguments are:
| 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. |
prepend(switch, short_opts, long_opts, nolong_opts)
# File optparse.rb, line 578 def prepend(*args) update(*args) @list.unshift(args[0]) end
Searches key in id list. The result is returned or yielded if a block is given. If it isn‘t found, nil is returned.
# File optparse.rb, line 603 def search(id, key) if list = __send__(id) val = list.fetch(key) {return nil} block_given? ? yield(val) : val end end
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 optparse.rb, line 632 def summarize(*args, &block) list.each do |opt| if opt.respond_to?(:summarize) # perhaps OptionParser::Switch opt.summarize(*args, &block) elsif !opt or opt.empty? yield("") else opt.each(&block) end end end
ruby-doc.org is hosted and maintained by James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, Arizona. The site was created in 2002 as part of the Ruby Documentation Project to promote the Ruby language and to help other Ruby hackers.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.