Skip to content

Instantly share code, notes, and snippets.

@nikushi
Created March 5, 2013 23:46
Show Gist options
  • Save nikushi/5095469 to your computer and use it in GitHub Desktop.
Save nikushi/5095469 to your computer and use it in GitHub Desktop.
example of optparse
require 'optparse'
opt = OptionParser.new
OPTS = {}
opt.on('-a') {|v| OPTS[:a] = v }
opt.on('-b') {|v| OPTS[:b] = v }
opt.parse!(ARGV)
p ARGV
p OPTS
#ruby sample.rb -a foo bar -b baz
# => ["foo", "bar", "baz"]
# {:a=>true, :b=>true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment