Ruby 错误“Cookie 类的超类不匹配” 来自 cgi.rb

发布于 2024-07-06 13:39:41 字数 294 浏览 11 评论 0原文

我刚刚将 gentoo 服务器上的 ruby​​ 安装更新为 ruby​​ 1.8.6 patchlevel 287,并且我的一个 eRuby 应用程序开始出现错误。 apache error_log 文件中给出的错误是:

[error] mod_ruby: /usr/lib/ruby/1.8/cgi.rb:774: superclass mismatch for class Cookie (TypeError)

奇怪的是,它有时似乎可以工作 - 但其他时候我会收到该错误。 有人有什么想法吗?

I've just updated my ruby installation on my gentoo server to ruby 1.8.6 patchlevel 287 and have started getting an error on one of my eRuby apps. The error given in the apache error_log file is:

[error] mod_ruby: /usr/lib/ruby/1.8/cgi.rb:774: superclass mismatch for class Cookie (TypeError)

The strange thing is that it seems to work sometimes - but other times I get that error. Anyone any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇女薄笑 2024-07-13 13:39:41

正如错误消息所示,代码中某处打开了 Cookie 类,该打开的超类与之前定义或打开 Cookie 类时使用的超类不同。

即使没有显式指定超类的类定义仍然有一个超类:

class Cookie
end

这用 Object 的超类定义了 Cookie 类。

我以前遇到过这个错误,当你有一些代码试图重新打开一个类而不指定超类时,就会发生这种错误,并且程序员的假设是该类(在本例中为 Cookie)已经被定义,并且他只是重新打开它以添加一些功能。 但是,如果重新打开和定义的顺序相反,您将收到该错误,因为该类已被定义为 Object 的子类,但正在尝试使用不同的超类重新定义或重新打开。 在 irb 中尝试一下:

% irb
irb(main):001:0> class C < String; end
=> nil
irb(main):002:0> class C; end
=> nil
irb(main):003:0> exit
% irb
irb(main):001:0> class C; end
=> nil
irb(main):002:0> class C < String; end
TypeError: superclass mismatch for class C
        from (irb):2

因此,您可能只需要 grep 查找 Cookie 类的定义,并尝试确保文件始终以正确的顺序进行 require-d。 这可能很容易,也可能不容易。 :)

As the error message says, there is an opening of the Cookie class somewhere in the code that is using a different superclass than the one used in a prior definition or opening of the Cookie class.

Even a class definition that does not explicitly specify a superclass still has a superclass:

class Cookie
end

This defines the Cookie class with the superclass of Object.

I've encountered this error before, and it will occur when you have some code trying to reopen a class without specifying the superclass, and the programmer's assumption is that the class (in this case, Cookie) has already been defined, and that he is simply reopening it to add some functionality. But if the reopening and the definition are in reverse order, you'll get that error because the class will already have been defined as a subclass of Object, but is trying to be redefined or reopened with a different superclass. Try this in irb:

% irb
irb(main):001:0> class C < String; end
=> nil
irb(main):002:0> class C; end
=> nil
irb(main):003:0> exit
% irb
irb(main):001:0> class C; end
=> nil
irb(main):002:0> class C < String; end
TypeError: superclass mismatch for class C
        from (irb):2

So, you probably just have to grep for definitions of the Cookie class and try to ensure files are always being require-d in the correct order. This may or may not be easy. :)

深空失忆 2024-07-13 13:39:41

当您重新声明已声明的类时,会出现该错误,很可能是因为您正在加载 cgi.rb 的两个不同副本。 请参阅 Rails 中的类似问题

That error shows up when you redeclare a class that’s already been declared, most likely because you’re loading two different copies of cgi.rb. See a similar issue in Rails.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文