Ruby uses single inheritance to keep the class hierarchy simple and avoid problems like the diamond problem that occur with multiple inheritance. Instead, Ruby uses modules to share code.
Ruby uses modules and mixins to add shared methods to classes. This allows code reuse without the complexity of multiple inheritance.
module M def greet "Hello from M" end end class A def greet "Hello from A" end end class B < A include M end puts B.new.greet
In Ruby, when a module is included in a class, its methods override those from the superclass. So B's greet method comes from module M.
module M1 def info "M1" end end module M2 def info "M2" end end class Parent def info "Parent" end end class Child < Parent include M1 include M2 end puts Child.new.info
Ruby's method lookup checks the last included module first, so M2's info method is called.
Ruby avoids multiple inheritance to prevent issues like the diamond problem and method conflicts. Instead, it uses modules to mix in behavior, providing flexibility without complexity.
