正如您在optparse.rb
(in /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/optparse.rb
for me)的代码文档中看到的那样==== Using Built-in Conversions
,您必须为方法指定第二个参数的字符串on
:
173 # ==== Using Built-in Conversions
174 #
175 # As an example, the built-in +Time+ conversion is used. The other built-in
176 # conversions behave in the same way.
177 # OptionParser will attempt to parse the argument
178 # as a +Time+. If it succeeds, that time will be passed to the
179 # handler block. Otherwise, an exception will be raised.
180 #
181 # require 'optparse'
182 # require 'optparse/time'
183 # OptionParser.new do |parser|
184 # parser.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |time|
185 # p time
186 # end
187 # end.parse!
188 #
因此
opt.on('-s','--service [String]','twitter (tw) or identica (id)') do |val|