tags:

views:

1002

answers:

2

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?

A: 

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.

Ben Stiglitz
+4  A: 

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. :)

Pistos