RUBYLIB 环境路径
所以目前我已将以下内容包含在我的 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与
PATH
类似,您需要显式命名要在其下查找库的目录。但是,这不会包含任何子目录,因此您还需要列出所有子子目录,并用冒号分隔它们。例如:
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:
正如 buruzaemon 提到的,Ruby 不搜索子目录,因此您需要在搜索路径中包含所需的所有目录。但是,您可能想要做的是:
这样您就不会依赖于以某种方式设置的 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:
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.