Multiple Inheritance in Ruby?

前端 未结 4 560
鱼传尺愫
鱼传尺愫 2021-02-01 15:04

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

4条回答
  •  面向向阳花
    2021-02-01 16:05

    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
    

    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
    

    And you surely cannot do this in Ruby.

提交回复
热议问题