Skip to content

Comment on Why composition is often better than inheritanceparent

Comments

You can only inherit from one class in ruby. You can mixin multiple modules into a class. So they aren't entirely equivalent.

Under the hood, mixing in modules actually is inheritance. An anonymous class is created that has all the module's methods, and this class is added to the inheritance hierarchy.

They are quite literally identical, even if Ruby tries it's best to hide that fact.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.