Ruby'requires'抛出NoMethodError's,堆栈跟踪显示Windows机器上的Unix路径 [英] Ruby 'requires' are throwing NoMethodError's, stack trace shows Unix paths on a Windows machine

查看:133
本文介绍了Ruby'requires'抛出NoMethodError's,堆栈跟踪显示Windows机器上的Unix路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图运行ruby脚本,但是在'require'语句上失败,抛出一个奇怪的错误:

Trying to run a ruby script, but it's failing on the 'require' statements, throwing a strange error:

代码:

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>'

任何想法可能是什么原因造成的?我最初的预感是,它与在Windows机器上运行时正在为Unix格式化的文件路径有关,但是我已将Ruby添加到PATH,所以我不知道为什么会这样而不是实际安装Ruby的位置(C:\ Ruby22-x64).

Any ideas what might be causing that? My initial hunch is that it has something to do with the file paths it's looking at being formatted for Unix while this is running on a Windows machine, but I've added Ruby to PATH, so I don't know why it would be looking there rather than where Ruby is actually installed (C:\Ruby22-x64).

为澄清起见,第一个require(对于'rubygems')不会引发错误,但是另一个require和require_relative都引发类似的错误.

To clarify, the first require (for 'rubygems') doesn't throw an error, but both the other requires and the require_relative all throw a similar one.

推荐答案

不能100%确定原因,但是从命令开头删除"ruby​​"即可解决此问题.因此,只需运行

Not 100% sure why, but removing the 'ruby' from the start of the command fixed it. So just running

my_script.rb

可以正常运行,但可以运行

works fine, but running

ruby my_script.rb

给出以上堆栈.

这篇关于Ruby'requires'抛出NoMethodError's,堆栈跟踪显示Windows机器上的Unix路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆