When I run this sample from the OptionParser documentation:
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: example.rb [options]"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
end
end.parse!
p options
p ARGV
and type: ruby test.rb -v 100
, it returns:
{:verbose=>true}
["100"]
Shouldn't verbose be 100
, not a boolean?
I have no idea about this, does anyone have any advice?
{:verbose=>true}
as well – Cocky--[no]verbose
specifies thatverbose
is a boolean switch. – Fumed