8.3. Nezpracované poznámky

Odkazy:

# Mandatory argument.
opts.on("-r", "--require LIBRARY", "Require the LIBRARY before executing your script") do |lib|
        options.library << lib
end
Optional argument; multi-line description.
opts.on("-i", "--inplace [EXTENSION]", "Edit ARGV files in place",
                                       "  (make backup if EXTENSION supplied)") do |ext|
        …
end
# Another typical switch to print the version.
opts.on_tail("--version", "Show version") do
        puts OptionParser::Version.join('.')
        exit
end

V dalším emailu je následující ukázka:

require 'rubygems'
require 'commandline'

class MyApp < CommandLine::Application
  def initialize
    # Mandatory argument
    option :names => %w(--require -r),
               :opt_description => "Require the LIBRARY "+
                                            "before executing your 
script",
               :arg_description => "LIBRARY",
               :opt_found => get_arg,
               :opt_not_found => required

    option :names => %w(--inplace -i),
               :arity => [0,1],
               :opt_description => "Edit ARGV files in place",
               :arg_description => "[EXTENSION]",
               :opt_found => get_arg,
  end

  def main
    #put your code here
    p opts
  end
end#class MyApp
opts.parse!(args)
Licence Creative Commons
Tento dokument Ruby, jehož autorem je Radek Hnilica, podléhá licenci Creative Commons Uveďte autora-Nevyužívejte dílo komerčně-Zachovejte licenci 3.0 Česká republika .