已安装的Ruby 1.9.3破坏了我的程序

时间:2022-07-19 15:59:08

Uh oh

哦哦

/Users/myname/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- classes/loginclass (LoadError)
    from /Users/myname/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from programtest.rb:1:in `<main>'

What have I done? This worked fine on 1.8.7 a few minutes ago; still works fine in TextMate which is running on 1.8.7. Do I need to change my folders somehow?

我做了什么?几分钟前,这个在1.8.7上运行得很好;在运行于1.8.7的TextMate中仍然运行良好。我需要改变我的文件夹吗?

EDIT:

编辑:

OK - was able to get it working with this edit:

好的-能够让它与这个编辑一起工作:

 require File.dirname(__FILE__) + '/classes/loginclass.rb'

Still don't understand why I had to change this. I guess my load path changed somehow?

还是不明白我为什么要改变这个。我猜我的负载路径不知怎么变了?

2 个解决方案

#1


4  

Do not write .rb at end of required file, also use File.join instead of slashes:

不要在需要的文件末尾写。rb,也要使用文件。加入代替斜杠:

require File.join(File.dirname(__FILE__), 'classes', 'loginclass')

#2


3  

In ruby 1.9.2+ it's better to use require_relative for this (very common) use case. And yes this problem did bite me too!

在ruby 1.9.2+中,最好对这个(非常常见的)用例使用require_relative。是的,这个问题也困扰了我!

#1


4  

Do not write .rb at end of required file, also use File.join instead of slashes:

不要在需要的文件末尾写。rb,也要使用文件。加入代替斜杠:

require File.join(File.dirname(__FILE__), 'classes', 'loginclass')

#2


3  

In ruby 1.9.2+ it's better to use require_relative for this (very common) use case. And yes this problem did bite me too!

在ruby 1.9.2+中,最好对这个(非常常见的)用例使用require_relative。是的,这个问题也困扰了我!