Module: Tins::ModuleGroup
- Defined in:
- lib/tins/module_group.rb
Overview
A module that allows grouping multiple modules together for type checking.
This implementation creates a shared module that gets included in each of the specified modules, enabling the use of ‘===` for type checking across all grouped modules simultaneously.
Class Method Summary collapse
-
.[](*modules) ⇒ Module
Creates a new module group from the given modules.
Class Method Details
.[](*modules) ⇒ Module
Note:
This modifies the included modules by adding the new module to their inheritance chain, which can have side effects in complex class hierarchies.
Creates a new module group from the given modules.
This method dynamically creates an anonymous module and includes it in each of the provided modules. The returned module can then be used with the ‘===` operator for type checking across all grouped modules.
30 31 32 33 34 35 36 |
# File 'lib/tins/module_group.rb', line 30 def self.[](*modules) modul = Module.new modules.each do |m| m.module_eval { include modul } end modul end |