RUBYLIB Environment Path

▼魔方 西西 提交于 2019-12-12 09:47:02

问题


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


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/5995305/rubylib-environment-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!