是否需要不带.rb扩展名的ruby文件? [英] Require ruby file without .rb extension?

查看:102
本文介绍了是否需要不带.rb扩展名的ruby文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个没有扩展名.rb的ruby文件,而是被标识为文件开头带有shebang的ruby代码.我想将此文件中的代码require放在另一个ruby文件中,但是似乎有问题,因为require自动将.rb扩展名附加到它要查找的文件中.有什么方法可以抑制这种行为,并使仅需要按给出的名称查找文件?

I have a ruby file that does not have a .rb extension, and is instead identified as ruby code with a shebang at the beginning of the file: #!/usr/bin/env ruby. I want to require the code in this file in another ruby file, but it seems to be having a problem because require automatically appends the .rb extension to the files it looks for. Is there any way to suppress this behavior and make require only look for the file as the name is given?

推荐答案

使用load代替:

load 'file-name'

这篇关于是否需要不带.rb扩展名的ruby文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆