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.
913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
# File 'lib/tins/dslkit.rb', line 913 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 |