【发布时间】:2016-04-28 09:04:37
【问题描述】:
我正在尝试使用 OptionParser 获取参数值。 我的代码只返回布尔值,而不是值:
require 'optparse'
options ={}
opts = OptionParser.new do |opts|
opts.on('-v') { |version| options[:version] = version }
opts.on('-g') { |branch| options[:branch] = branch }
opts.on('-f') { |full| options[:full] = full }
opts.on('-h') { RDoc::usage }
end.parse!
# mandatory options
if (options[:version] == nil) or (options[:branch] == nil) or (options[:full]== nil) then
puts options[:branch]
puts options[:version]
puts options[:full]
RDoc::usage('usage')
end
puts options[:branch]
---> 是的
有什么想法吗?
【问题讨论】: