Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ruby 如何支持多重继承,以便我可以从多个类继承?
Ruby 没有直接的多重继承。Ruby 也有类似的东西:mixins。例如:
module M; end module N; end class C include M include N end C.ancestors #=> [C, N, M, Object, Kernel, BasicObject]
请注意,mixin不是多重继承,而是基本上消除了对它的需求。