开发者

How to add something to Ruby's load path

开发者 https://www.devze.com 2022-12-10 07:18 出处:网络
I want to add a folder \"~/Projects/Scripts\" to use require *script* where *script* is a Ruby file in开发者_运维问答 this directory.

I want to add a folder "~/Projects/Scripts" to use require *script* where *script* is a Ruby file in开发者_运维问答 this directory.

How does the require method work? Does it load from a environment variable and if so what?


$LOAD_PATH or $: or $-I is array of string holding the directories to be searched when load the files with the load or require methods. You can append new directories as you did for normal array.

 >> $:
 => ["deleted_for_simplicity","/usr/lib/ruby/1.8/i386-linux", "."]

 >> $: << "/opt/project"
 => ["deleted_for_simplicity","/usr/lib/ruby/1.8/i386-linux", ".", "/opt/project"]


See "How to set Ruby's load path externally".

The answer is that you set the RUBYLIB environment variable to add items to the list of paths that Ruby searches.

0

精彩评论

暂无评论...
验证码 换一张
取 消