TypeError: superclass mismatch for class Word in Ruby
A thumb rule for irb (either way irb
or rails console
)
If you are creating the same class twice with inheritance (superclass), exit the irb instance and create it again. Why this? Because otherwise class conflicts will happen.
In your case, you are using Windows (found from the question), so just type exit
on DOS prompt and again type irb
or rails console
and create your Word class and it should work. Please let me know if it doesn't work for you.
Superclass mismatch for class in Ruby
lib/command/group/add.rb
may get loaded before lib/command/group.rb
. Hence in the latter, it appears as if you try to change which class Group
inherits from.
The band aid solution would be to point to the same subclass in all files. Aka in lib/command/group/add.rb
, you should add < Command
.
The real solution should be to never use a class/module for namespacing and attach functionality to it.
This issue was raised in Euruko 2016 and Matz said they might consider a special keyword for it. [Citation needed]
Ruby on Rails 3 : superclass mismatch for class ...
You already have a Word
class defined elsewhere. I tried within a Rails 3 app but was not able to replicate.
If you have not created a second Word
class yourself, it is likely one of your Gems or plugins already defines it.
Superclass mismatch for class
The Email
class must already be defined somewhere else.
You can test that by using the defined?
method like this:
defined?(Email)
Think about namespacing your code by using a module:
module MyNameSpace
class MyClass
end
end
Looks like you need to remove the definition from the CodeAcademy Context. Try deleting your browser cookies and refreshing the page.
superclass mismatch for class Queue (TypeError)
The script adds a class Queue
like this:
class Queue < Debitable
end
Ruby 2.1 introduced its own Queue
class which inherits from Object
. This leads to the error you mention.
Following script demonstrates the problem:
class Thing < Object
end
class Thing < String
end
If you run it then Ruby will tell you that it has a superclass mismatch for class Thing (TypeError)
Two ways to solve this:
- Use Ruby < 2.1 so the
Queue
class does not exist (which is kind of sad and not recommended) - update the script, replace all occurences of
Queue
withMyQueue
(you are free to come up with a better name)
Potentially a 6 year old script contains other problems as well... so good luck.
Also: if you really need different ruby version you can look at a ruby version manager like RVM or RBEnv.
` module:Rails ': superclass mismatch for class Server (TypeError)
A better way to do what you want:
require 'rails/commands/server'
module DefaultOptions
def default_options
super.merge!(Port: 8081)
end
end
Rails::Server.prepend(DefaultOptions)
The reason for the error message is because you are attempting to redefine the Rails::Server
class and changing it's inheritance structure. Rails::Server
inherits from ::Rack::Server
, however your code is trying to say it no longer does. Therefore, you get your superclass mismatch error.
Related Topics
Iterate Over a Deeply Nested Level of Hashes in Ruby
Sum the Value of Array in Hash
Typeerror: Superclass Mismatch for Class Word in Ruby
Store the Day of the Week and Time
Equivalent of "Continue" in Ruby
How to Return Early from a Rake Task
Checking If a Variable Is an Integer
Difference Between @Instance_Variable and Attr_Accessor
What Does 'Def Self.Function' Name Mean
Redefining a Single Ruby Method on a Single Instance with a Lambda
(Ruby) Getting Net::Smtp Working with Gmail...
Ruby on Rails Rmagick on Windows 7
Differencebetween <%= ... %> and <% ... %> in Ruby on Rails
Tell Ruby Program to Wait Some Amount of Time