Neither ruby and nor irb can load .rb file in current directory

不羁岁月 提交于 2019-12-02 17:30:49

None of these worked for me, but this did:

irb -I .
>require 'file'
 => true
require './hede'

or

require_relative 'hede'

This works for me in both Ruby (1.9.3) and JRuby (1.7.x) on linux. I haven't tested it on windows.

Noticed the same behavior but my linux roots had me try:.\file.rb and it loaded into the irb. Try explicitly declaring the current directory.

How about this command? A little cumbersome to write but really clean and it should always work:

➜ $ irb
> require "#{Dir.pwd}/file_to_load.rb"
=> true 
quetzalcoatl

it's damn dirty, but you can always do at the very first line:

$: << '.'

and off you go with pwd'ed require. It's quite useful for interactive/creative testing with IRB

I believe both of the previous posts are correct, just for different uses. In IRB use an absolute path with require, with a file you can also use require with an absolute path, or use require_relative.

awsmsce

If you're trying to do this with rvmsudo, I found this worked for me:

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