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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.