我有一个充满红宝石文件的文件夹,当我尝试使用require 'file'在同一目录中的另一个文件中需要一个文件时,我得到一个LoadError,但是当我使用require './file'时,一切正常.有人可以向我解释为什么会发生这种情况吗?是否可以在没有添加./的情况下以某种方式要求文件?
I have a folder full of ruby files, and when I try and require one file in another that is in the same directory using require 'file' I get a LoadError but when I use require './file' everything works fine. Can somebody explain to me why this happens and if there is any way I can require a file without adding a ./ onto the file?
(目录图片):
推荐答案如果要不是从系统$LOAD_PATH而是相对于文件目录来require的文件,则正在require定义从开始,您应该使用 require_relative . (如您所见,没有完全广泛记录.)
If you want to require a file not from the system $LOAD_PATH but rather relative to the directory of the file you are requireing from, you should use require_relative. (Which, as you can see, isn't exactly extensively documented.)
更多推荐
Ruby要求'file'不起作用,但要求'./file'起作用.为什么?
发布评论