RUBYLIB 环境路径

发布于 2024-11-07 06:35:16 字数 416 浏览 0 评论 0原文

所以目前我已将以下内容包含在我的 .bashrc 文件中。

export RUBYLIB=/home/git/project/app/helpers

规范来运行 rspec

require 'output_helper'

我正在尝试使用具有此文件位于 helpers 目录中的 。我的问题是,当我将导出行更改为:

export RUBYLIB=/home/git/project/

它不再找到帮助程序文件。我认为 ruby​​ 应该搜索我提供的整个路径,而不仅仅是提供的最外层目录?这是正确的思考方式吗?如果没有,我怎样才能让 RUBY 搜索所有子目录及其子目录等?

谢谢,

罗宾

So currently I have included the following in my .bashrc file.

export RUBYLIB=/home/git/project/app/helpers

I am trying to run rspec with a spec that has

require 'output_helper'

This file is in the helpers directory. My question is that when I change the export line to:

export RUBYLIB=/home/git/project/

It no longer finds the helper file. I thought that ruby should search the entire path I supply, and not just the outermost directory supplied? Is this the correct way to think about it? And if not, how can I make it so RUBY will search through all subdirectories and their subdirectories, etc?

Thanks,

Robin

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

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

发布评论

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

评论(2

可爱暴击 2024-11-14 06:35:16

PATH 类似,您需要显式命名要在其下查找库的目录。但是,这不会包含任何子目录,因此您还需要列出所有子子目录,并用冒号分隔它们。

例如:

export RUBYLIB=/home/git/project:/home/git/project/app/helpers

Similar to PATH, you need to explicitly name the directory under which to look for libraries. However, this will not include any child directories within, so you will need to list any child sub-directories as well, delimiting them with a colon.

For example:

export RUBYLIB=/home/git/project:/home/git/project/app/helpers
记忆消瘦 2024-11-14 06:35:16

正如 buruzaemon 提到的,Ruby 不搜索子目录,因此您需要在搜索路径中包含所需的所有目录。但是,您可能想要做的是:

require 'app/helpers/output_helper'

这样您就不会依赖于以某种方式设置的 RUBYLIB 环境变量。当您将代码部署到生产环境或与其他人协作时,这些小的依赖关系可能会导致烦人的调试会话。

另请注意,您可以指定 . 作为搜索路径,而不是使用特定于计算机的绝对路径。

As buruzaemon mentions, Ruby does not search subdirectories, so you need to include all the directories you want in your search path. However, what you probably want to do is:

require 'app/helpers/output_helper'

This way you aren't depending on the RUBYLIB environment variable being set a certain way. When you're deploying code to production, or collaborating with others, these little dependencies can make for annoying debugging sessions.

Also as a side note, you can specify . as a search path, rather than using machine-specific absolute paths.

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