Multiple Inheritance in Ruby?

前端 未结 4 594
鱼传尺愫
鱼传尺愫 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 15:46

    No, multi inheritance means one class have more than one parent class. For example in ruby you can have that behavior with modules like:

    class Thing
      include MathFunctions
      include Taggable
      include Persistence
    end
    

    So in this example Thing class would have some methods from MathFunctions module, Taggable and Persistence, that wouldn't be possible using simple class inheritance.

提交回复
热议问题