Tutorial by Examples

It's relatively easy to parse the command line by hand if you aren't looking for anything too complex: # Naive error checking abort('Usage: ' + $0 + ' site id ...') unless ARGV.length >= 2 # First item (site) is mandatory site = ARGV.shift ARGV.each do | id | # Do something interestin...
With OptionsParser, it's really easy to set up default values. Just pre-populate the hash you store the options in: options = { :directory => ENV['HOME'] } When you define the parser, it will overwrite the default if a user provide a value: OptionParser.new do |opts| opts.on("-d&...
Sometimes your description can get rather long. For instance irb -h lists on argument that reads: --context-mode n Set n[0-3] to method to create Binding Object, when new workspace was created It's not immediately clear how to support this. Most solutions require adjustin...

Page 1 of 1