Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why it's impossible to include class in Ruby?

Tags:

module

class

ruby

Why "Class < Module" in Ruby, but I can't include class into other class? What is the technical difference between class and module except that the class can be inherited from another?

like image 502
user123980801 Avatar asked Dec 16 '25 20:12

user123980801


1 Answers

That is exactly the difference between Classes and Modules in Ruby - Modules can be included and Classes cannot. It is simply the design of the language.

Classes are intended to provide concrete functionality open for extension and Modules provide namespaces and mixin capabilities. The reason for this difference is probably related to the idea of mixins as replacement for multiple inheritance and interfaces.

like image 60
maerics Avatar answered Dec 19 '25 23:12

maerics



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!