红宝石“需要”扔NoMethodError的,堆栈跟踪显示在Windows机器上的Unix路径(Ru

2019-10-28 17:57发布

尝试运行Ruby脚本,但它的失败在“要求”语句,抛出一个奇怪的错误:

码:

require "rubygems"
require "bundler/setup"
require_relative "plugins/pivotal_rabbitmq_plugin/pivotal_rabbitmq_plugin.rb"
require "newrelic_plugin"

module PivotalAgent
  NewRelic::Plugin::Config.config_file=File.dirname(__FILE__) + "/config/newrelic_plugin.yml"
  NewRelic::Plugin::Run.setup_and_run
end

命令:

ruby pivotal_agent.rb

错误:

/usr/share/rubygems/rubygems/path_support.rb:78:in `path=': undefined method `+' for nil:NilClass (NoMethodError)
        from /usr/share/rubygems/rubygems/path_support.rb:34:in `initialize'
        from /usr/share/rubygems/rubygems.rb:325:in `new'
        from /usr/share/rubygems/rubygems.rb:325:in `paths'
        from /usr/share/rubygems/rubygems.rb:348:in `path'
        from /usr/share/rubygems/rubygems/specification.rb:872:in `dirs'
        from /usr/share/rubygems/rubygems/specification.rb:750:in `stubs'
        from /usr/share/rubygems/rubygems/specification.rb:938:in `find_inactive_by_path'
        from /usr/share/rubygems/rubygems.rb:186:in `try_activate'
        from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
        from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:39:in `require'
        from pivotal_agent.rb:2:in `<main>'

任何想法可能会导致什么? 我最初的直觉是,它是与它的看着被格式化为Unix,而这是在Windows机器上运行的文件路径,但我已经添加了Ruby来PATH,所以我不知道为什么会在看存在,而不是其中实际安装红宝石(C:\ Ruby22-x64)的。

编辑:为了澄清,首先需要(为“RubyGems的”)不会引发错误,但两者的其他要求和require_relative都会抛出一个类似。

Answer 1:

没有100%地知道为什么,但除去固定它的命令开始的“红宝石”。 因此,只要运行

my_script.rb

工作正常,但运行

ruby my_script.rb

给出上述堆栈。



文章来源: Ruby 'requires' are throwing NoMethodError's, stack trace shows Unix paths on a Windows machine