Module: Tins::ParameterizedModule

Included in:
Module, FromModule
Defined in:
lib/tins/dslkit.rb

Overview

A module that provides parameterization capabilities for other modules.

This module enables dynamic configuration of modules through a common interface, allowing for flexible composition and customization of module behavior at runtime.

Examples:

Basic usage with a custom parameterizable module

module MyModule
  include Tins::ParameterizedModule

  def self.parameterize(options = {})
    # Custom parameterization logic
    @options = options
    self
  end
end

# Usage
configured_module = MyModule.parameterize_for(some_option: 'value')
MyModule.instance_variable_get(:@options) # => {some_option: "value"}

Instance Method Summary collapse

Instance Method Details

#parameterize_for(*args) {|block| ... } ⇒ Module

Configures the module using the provided arguments and optional block.

This method checks if the including module responds to ‘parameterize` and calls it with the given arguments. If no `parameterize` method exists, it returns the module itself unchanged.

Parameters:

  • args (Array)

    Arguments to pass to the parameterize method

Yields:

  • (block)

    Optional block to be passed to the parameterize method

Returns:

  • (Module)

    The configured module or self if no parameterization occurs



862
863
864
# File 'lib/tins/dslkit.rb', line 862

def parameterize_for(*args, &block)
  respond_to?(:parameterize) ? parameterize(*args, &block) : self
end