我正在尝试在我正在构建的应用程序中使用Ruby gem Mechanize,但是我收到了错误。
使用Ruby 1.9.3-p0在IRB中执行以下操作:
require 'Mechanize'
agent = Mechanize.new
page = agent.get('http://www.google.com')
给我以下错误:
NoMethodError: undefined method `info' for nil:NilClass
from ~/.rvm/gems/ruby-1.9.3-p0@global/gems/net-http-spy-0.2.1/lib/net-http-spy.rb:24:in 'initialize'
net-http-spy.rb的初始化块如下所示:
def initialize(*args, &block)
self.class.http_logger_options ||= {}
defaults = {:body => false, :trace => false, :verbose => false, :limit => -1}
self.class.http_logger_options = (self.class.http_logger_options == :default) ? defaults : self.class.http_logger_options
@logger_options = defaults.merge(self.class.http_logger_options)
@params_limit = @logger_options[:params_limit] || @logger_options[:limit]
@body_limit = @logger_options[:body_limit] || @logger_options[:limit]
self.class.http_logger.info "CONNECT: #{args.inspect}" if !@logger_options[:verbose]
old_initialize(*args, &block)
@debug_output = self.class.http_logger if @logger_options[:verbose]
end
它似乎是引发问题的self.class.http_logger.info
行,我只是不确定原因。任何人都能明白我做错了吗?