Ruby要求'file'不起作用,但要求'.​​/file'起作用.为什么?

编程入门 行业动态 更新时间:2024-10-23 22:32:38
本文介绍了Ruby要求'file'不起作用,但要求'.​​/file'起作用.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个充满红宝石文件的文件夹,当我尝试使用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'起作用.为什么?

本文发布于:2023-11-01 23:11:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550682.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   Ruby   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!