Ruby on Rails 3:“类的超类不匹配......" [英] Ruby on Rails 3 : "superclass mismatch for class ..."

查看:34
本文介绍了Ruby on Rails 3:“类的超类不匹配......"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

平台:Mac OSX 10.6

Platform: Mac OSX 10.6

在我的终端中,我使用rails c"启动 Ruby 控制台

In my terminal, i start the Ruby console with "rails c"

按照 Ruby on Rails 3 教程构建类:

While following the Ruby on Rails 3 tutorial to build a class:

class Word < String 
  def palindrome? #check if a string is a palindrome
    self == self.reverse
  end
end

我收到错误消息:

TypeError: superclass mismatch for class Word
    from (irb):33
    from /Users/matthew/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.5/lib/rails/commands/console.rb:44:in `start'
    from /Users/matthew/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.5/lib/rails/commands/console.rb:8:in `start'
    from /Users/matthew/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.5/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

教程显示没有问题,我知道代码没问题;我搜索了其他相关问题,但它们都涉及从 Ruby 2 迁移到 3 或 erb vs eruby.

The tutorial shows that it has no problem and i know the code is fine; I've searched other related questions, but they all involved migrating from Ruby 2 to 3 or erb vs eruby.

推荐答案

您已经在别处定义了 Word 类.我在 Rails 3 应用程序中尝试过,但无法复制.

You already have a Word class defined elsewhere. I tried within a Rails 3 app but was not able to replicate.

如果您还没有自己创建第二个 Word 类,很可能您的 Gems 或插件之一已经定义了它.

If you have not created a second Word class yourself, it is likely one of your Gems or plugins already defines it.

这篇关于Ruby on Rails 3:“类的超类不匹配......"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆