Module: Paramix::Parametric

Defined in:
lib/paramix.rb

Overview

Parametric

Parametric mixins provides parameters for mixin modules. Module parameters can be set at the time of inclusion or extension using Module#[] method, then parameters can be accessed via the #mixin_parameters method.

module MyMixin
  include Paramix::Parametric

  parameterized |params|
    define_method :hello do
      puts "Hello from #{params[:name]}!"
    end
  end
end

class MyClass
  include MyMixin[:name => 'Ruby']
end

MyClass.new.hello   #=> 'Hello from Ruby!'

Defined Under Namespace

Modules: Extensions Classes: Mixin

Class Method Summary (collapse)

Class Method Details

+ (Object) included(base)



37
38
39
# File 'lib/paramix.rb', line 37

def self.included(base)
  base.extend(Extensions)
end