这是我第一次使用OptionParser,我收到了这个错误:
/Users/jay/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mechanize-> 2.7.3 / lib / mechanize / http / agent.rb:651:in
resolve': absolute URL needed (not -v) (ArgumentError)from /Users/jay/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mechanize-2.7.3/lib/mechanize/http/agent.rb:223:in
fetch' 来自/Users/jay/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mechanize-2.7.3/lib/mechanize.rb:440:inget' from /Users/jay/Code/linkedin-scraper/lib/myModel-scraper/profile.rb:20:in
initialize' 来自./bin/myModel-scraper:6:innew' from ./bin/myModel-scraper:6:in
'
滨:
require 'rubygems'
require 'optparse'
opts = OptionParser.new do |opts|
opts.on_tail("-v", "--version", "Show version") { puts myModel::Scraper::VERSION; exit }
opts.parse!
end
LIB /版本:
module myModel
module Scraper
VERSION = '0.1.2'
end
end
我想我完全错了,有人可以解释一下这里发生了什么吗?
答案 0 :(得分:0)
我通常会像这样写一个OptionParser块:
OptionParser.new do |opts|
opts.on_tail("-v", "--version", "Show version") { puts myModel::Scraper::VERSION; exit }
end.parse!
我可能会使用on
代替on_tail
:
opts.on("-v", "--version", "Show version") { puts myModel::Scraper::VERSION; exit }
但我明白为什么你可能希望它出现在帮助列表的末尾。