Module là tập hợp method và constant — không thể khởi tạo, không thể kế thừa. Hai vai trò chính:
1. Namespace — tránh trùng tên: Payments::Invoice vs Mailer::Invoice.
2. Mixin — include vào class để chia sẻ method.
| Class | Module | |
|---|---|---|
| Khởi tạo | new | Không |
| Kế thừa | < | Không |
| Mixin | Không | include / extend / prepend |
A module is a collection of methods and constants — it cannot be instantiated and cannot be inherited from. Two main roles:
1. Namespace — prevent name clashes: Payments::Invoice vs Mailer::Invoice.
2. Mixin — include into classes to share methods.
| Class | Module | |
|---|---|---|
| Instantiation | new | No |
| Inheritance | < | No |
| Mixin | No | include / extend / prepend |