Ruby 要求“没有要加载的文件”路径中存在错误但很明显

发布于 2024-09-29 20:32:58 字数 991 浏览 0 评论 0原文

我一直在尝试获取一个 ruby​​ 文件来需要另一个 ruby​​ 文件,我觉得我快要疯了。我的设置如下

'/raid1/ruby-code/benchmark/' 中的两个文件

CommandRunner
Benchmarker

Benchmarker 此时是主程序,并且需要 CommandRunner,我尝试了很多不同的东西,但没有一个起作用。以下是我在 Benchmarker 开头放置的所有内容的列表,

require 'CommandRunner'
require './CommandRunner'
$LOAD_PATH.unshift File.expand_path(File.dirname($PROGRAM_NAME))
require 'CommandRunner'
$LOAD_PATH.unshift File.expand_path(File.dirname($PROGRAM_NAME))
require './CommandRunner'

我还使用 require_relative 尝试了上述所有排列。我尝试过将文件加载到 emacs 内的 irb 中,并且我在命令行中尝试过。在 irb 中的某个时刻,它会加载一次

require 'CommandRunner'
and then would load until I switched it back to './CommandRunner' and then it would load once again.

我实际上遇到了错误,

`require_relative': no such file to load -- 
/raid1/ruby-code/benchmark/CommandRunner (LoadError)

这是文件的正确路径!

我已经将其切换为加载并且似乎正在工作,我看到奇怪的行为但这可能就是我。有谁知道这里会发生什么吗?

I've been trying to get a ruby file to require another ruby file and I feel like I'm going crazy. My setup is as follows

Two files in '/raid1/ruby-code/benchmark/'

CommandRunner
Benchmarker

Benchmarker is the main program at this point and wants to require CommandRunner, I've tried a bunch of different things and none of them work. The following is a list of all of the things I've put at the beginning of Benchmarker

require 'CommandRunner'
require './CommandRunner'
$LOAD_PATH.unshift File.expand_path(File.dirname($PROGRAM_NAME))
require 'CommandRunner'
$LOAD_PATH.unshift File.expand_path(File.dirname($PROGRAM_NAME))
require './CommandRunner'

I've also tried all of the above permutations using require_relative. I've tried it loading the file into irb inside of emacs, and I've tried it at the command line. At one point in irb it would load once with

require 'CommandRunner'

and then would load until I switched it back to './CommandRunner' and then it would load once again.

I've actually had the error say

`require_relative': no such file to load -- 
/raid1/ruby-code/benchmark/CommandRunner (LoadError)

which is the correct path to the file!

I've since switched it to load and that seems to be working, I'm seeing weird behavior but that just might be me. Does anyone have any idea what would be going on here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半边脸i 2024-10-06 20:32:58

文件名是 CommandRunner 而不是 CommandRunner.rb 吗? ruby 文件的标准命名约定是使用小写字母和下划线,因此即使类名是 CommandRunner,文件也将是 command_runner.rb,然后 require 'command_runner' 应该可以工作。

Is the name of the file CommandRunner and not CommandRunner.rb? The standard naming convention for ruby files is to use lowercase and underscores, so even though the class name would be CommandRunner, the file would be command_runner.rb, and then require 'command_runner' should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文