更新:
我找到了简单的答案,这完全是我自己的错:我将上述代码存储在名为“eventmachine.rb”的文件中。因此,当我需要“eventmachine”时,它只是导入相同的文件,其中不包含 EventMachine 的定义。
所以这并不是一篇关于 EventMachine 的文章。
原帖:
请问,这是怎么回事?
require 'rubygems'
require 'eventmachine'
EventMachine
都会给出
uninitialized constant EventMachine
当我运行“ruby myfile.rb”时,在 TextMate 和控制台上
。但如果我在 IRB 中输入相同的内容,我会得到
=> EventMachine
.
...
我非常沮丧,以至于我按照 http://blog.carlmercier.com/2007/12/14/how-to-fix-that-rubygems-mess-on-leopard/ -- 清除我的 Ruby 和 Rubygems环境并从 MacPorts 重新安装它们。 IRB 仍然有效,TextMate/命令行仍然以同样的方式失败。我什至将 TextMate 路径减少到现在安装 Ruby、Gem 和 IRB 的位置:/opt/local/bin——这就是 Which 报告的内容。
最后,当我
puts Gem.path
在 IRB、TextMate 或控制台上时,我得到相同的路径。
UPDATE:
I found the simple answer and it's completely my own fault: I stored the above code in a file called "eventmachine.rb". Thus when I required 'eventmachine' it just imported the same file, which does not contain a definition for EventMachine.
So this is not really a post about EventMachine.
ORIGINAL POST:
Excuse me, but what's going on?
require 'rubygems'
require 'eventmachine'
EventMachine
gives
uninitialized constant EventMachine
in both TextMate and on the console when I run "ruby myfile.rb".
But if I type the same thing into IRB, I get
=> EventMachine
.
...
I got so frustrated that I followed the rash instructions on http://blog.carlmercier.com/2007/12/14/how-to-fix-that-rubygems-mess-on-leopard/ -- wiping out my Ruby and Rubygems environments and reinstalling them from MacPorts. IRB still works and TextMate/commandline still fails in the same way. I even reduced my TextMate PATH to the one place where Ruby, Gem, and IRB are installed now: /opt/local/bin -- which is what Which reports.
Finally, when I
puts Gem.path
on either IRB, TextMate, or the console, I get the same path.
发布评论
评论(3)
我找到了简单的答案,这完全是我自己的错:
我将上述代码存储在名为“eventmachine.rb”的文件中。因此,当我需要“eventmachine”时,它只是导入相同的文件,其中不包含 EventMachine 的定义。
I found the simple answer and it's completely my own fault:
I stored the above code in a file called "eventmachine.rb". Thus when I required 'eventmachine' it just imported the same file, which does not contain a definition for EventMachine.
你安装了gem吗?
通常,像您显示的代码中那样的错误是因为该行
失败并且未定义类/模块常量 EventMachine。
另外,如果您运行的是 ruby 1.9,则不再需要
Have you installed the gem?
Typically an error like that in the code you show is because the line
failed and that class/module constant, EventMachine, is not defined.
Also, if you are running ruby 1.9, you no longer need to have
我不明白为什么消息是“未初始化常量”,但问题是您没有提供任何运行内容。我在你的代码中遇到了同样的错误,但如果我将其更改为:
那么它的工作原理完全符合我的预期 - 它每秒打印 10 点。
I don't understand why the message is "Uninitialized Constant", but the problem is that you provided nothing to run. I get the same error with your code, but if I change it to:
then it works exactly as I expect - it prints 10 dots per second.