Module: Tins::FromModule
Overview
A module that provides parameterized module creation capabilities.
This module enables the creation of new modules by filtering methods from existing modules, allowing for flexible composition and interface segregation at runtime.
Instance Method Summary collapse
-
#parameterize(opts = {}) ⇒ Module
Creates a new module by filtering methods from an existing module.
Methods included from ParameterizedModule
Instance Method Details
#parameterize(opts = {}) ⇒ Module
Creates a new module by filtering methods from an existing module.
This method duplicates the specified module and removes all methods except those explicitly listed in the :methods option. This enables creating specialized interfaces from existing modules.
931 932 933 934 935 936 937 938 939 940 941 942 943 944 |
# File 'lib/tins/dslkit.rb', line 931 def parameterize(opts = {}) modul = opts[:module] or raise ArgumentError, 'option :module is required' import_methods = Array(opts[:methods]) result = modul.dup remove_methods = modul.instance_methods.map(&:to_sym) - import_methods.map(&:to_sym) remove_methods.each do |m| begin result.__send__ :remove_method, m rescue NameError # Method might already be removed or not exist end end result end |