Created
March 5, 2013 23:46
-
-
Save nikushi/5095469 to your computer and use it in GitHub Desktop.
example of optparse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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