ruby和nor irb都不能在当前目录中加载.rb文件 [英] Neither ruby and nor irb can load .rb file in current directory
本文介绍了ruby和nor irb都不能在当前目录中加载.rb文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Ruby中导入文件时遇到了麻烦。我在Windows XP中制作一个Ruby应用程序。该应用程序的所有类文件都在C:/ Documents / Prgm / Surveyor_Ruby / lib
中。但当我要求
另一个文件中的文件时,ruby和irb都无法找到所需的文件。
I'm having a really noob problem with importing files in Ruby. I'm making a Ruby app in Windows XP. All the class files for the app are in "C:/Documents/Prgm/Surveyor_Ruby/lib"
. But when I require
a file in another file, neither ruby nor irb can find the required file.
当前目录的内容:
C:\Documents\Prgm\Surveyor_Ruby\lib>dir
Volume in drive C has no label.
Volume Serial Number is AAAA-BBBB
Directory of C:\Documents\Prgm\Surveyor_Ruby\lib
10/09/2010 06:32 PM <DIR> .
10/09/2010 06:32 PM <DIR> ..
10/08/2010 03:22 PM 5,462 main (commented).rb
10/08/2010 03:41 PM 92 question.rb
10/08/2010 09:06 PM 2,809 survey.rb
10/09/2010 06:25 PM 661 surveyor.rb
10/08/2010 01:39 PM 1,546 test.rb
5 File(s) 10,570 bytes
2 Dir(s) 40,255,045,632 bytes free
确认irb在正确的目录中:
Confirmation that irb is in correct directory:
C:\Documents\Prgm\Surveyor_Ruby\lib>irb
irb(main):001:0> Dir.pwd
=> "C:/Documents/Prgm/Surveyor_Ruby/lib"
...但是irb无法加载survey.rb:
...yet irb can't load survey.rb:
irb(main):002:0> require 'survey'
LoadError: no such file to load -- survey
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from (irb):2
from C:/Ruby192/bin/irb:12:in `<main>'
推荐答案
这些都不适合我,但这样做了:
None of these worked for me, but this did:
irb -I .
>require 'file'
=> true
这篇关于ruby和nor irb都不能在当前目录中加载.rb文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文