Command-Line Programs
Option Values
An option can take the next argument as its value.
Option Values
option_values.rb
args =
limit_index = args.index("--limit")
raw_limit = limit_index ? args[limit_index + 1] : nil
display_limit = raw_limit || "none"
limit = raw_limit ? raw_limit.to_i : 10
limit = 1 if limit < 1
puts "args=#{args.join(' ')}"
puts "raw_limit=#{display_limit}"
puts "limit=#{limit}"
puts "bounded=#{limit >= 1}"
args =
limit_index = args.index("--limit")
raw_limit = limit_index ? args[limit_index + 1] : nil
display_limit = raw_limit || "none"
limit = raw_limit ? raw_limit.to_i : 10
limit = 1 if limit < 1
puts "args=#{args.join(' ')}"
puts "raw_limit=#{display_limit}"
puts "limit=#{limit}"
puts "bounded=#{limit >= 1}"
args =
limit_index = args.index("--limit")
raw_limit = limit_index ? args[limit_index + 1] : nil
display_limit = raw_limit || "none"
limit = raw_limit ? raw_limit.to_i : 10
limit = 1 if limit < 1
puts "args=#{args.join(' ')}"
puts "raw_limit=#{display_limit}"
puts "limit=#{limit}"
puts "bounded=#{limit >= 1}"
option value
After finding an option name, read the following array entry and validate a default when it is missing.