Ruby中的多重继承? [英] Multiple Inheritance in Ruby?

查看:98
本文介绍了Ruby中的多重继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为Ruby除了mixin之外只允许单继承。但是,当我的类 Square 继承了类 Thing Thing 默认继承对象

I thought that Ruby only allowed single inheritance besides mixin. However, when I have class Square that inherits class Thing, Thing in turn inherits Object by default.

class Thing
end

class Square < Thing
end

这不代表多重继承吗?

推荐答案

我认为你正在以错误的方式理解多重继承的含义。可能你想到的是多重继承是这样的:

I think you are taking the meaning of multiple inheritance in a wrong way. Probably what you have in mind as multiple inheritance is like this:

class A inherits class B
class B inherits class C

如果是这样,那就错了。这不是多继承的原因,Ruby也没有问题。多重继承的真正含义是:

If so, then that is wrong. That is not what multiple inheritance is, and Ruby has no problem with that. What multiple inheritance really means is this:

class A inherits class B
class A inherits class C

你肯定不能用Ruby做到这一点。

And you surely cannot do this in Ruby.

这篇关于Ruby中的多重继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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