Sunday, June 29, 2008

superclass mismatch

A 'superclass mismatch'  is ruby's way of telling you that you're trying to define/open a class who's superclass is different than what its previously recorded. An example:

irb(main):001:0> class Foo; end
=> nil
irb(main):002:0> class Bar; end
=> nil
irb(main):003:0> class Baz < Foo; end
=> nil
irb(main):004:0> class Baz < Bar; end
TypeError: superclass mismatch for class Baz
from (irb):4
from :0

What this usually means is that you're using a name thats already been used, and often you may not realize it. Earlier today someone in #merb had this exact issue when trying to define a class named Region. So, if you see this error popup, you can usually rename your class to something else to make sure the name is unique and that you're not inadvertently reopening a previously defined class.

1 comment:

Maximus said...

Thanks, I'd copy/pasted a class file and forgot to change the name of the class :)