Skip to content
This repository was archived by the owner on Nov 20, 2026. It is now read-only.
rubyunworksPublic archive

About

Parmetric Mixins

Resources

Stars

25 stars

Watchers

0 watching

Forks

Latest commit

 

History

52 Commits

Folders and files

Repository files navigation

This project is retired.

Paramix is now part of Ruby Facets, since Facets 4.2.0 (2026-11): require 'facets/paramix'. A parametric module says include Paramix, and include Paramix::Parametric still works, so code written for this gem runs unchanged. This gem is no longer needed.

This repository preserves Paramix, last released as 2.0.1 in 2011. It is no longer maintained.


Paramix

Gem Version Build Status     Flattr Me

Website · YARD API · Report Issue · Source Code

About

Parametric Mixins provides an easy means to "functionalize" modules. The module can then be differentiated upon usage according to the parameters provided.

Usage

Here is the most basic example. It simply makes the parametric module's parameters available at the instance level.

module M
  include Paramix::Parametric

  paramaterized do |params|
    define_method :params do
      params
    end
  end

  def hello
    "Hello, %s!" % [params[:name]]
  end
end

class X
  include M[:name=>'Charlie']
end

X.new.hello  #=> 'Hello, Charlie!'

Because the +parameterized+ method defines a block that is evaluated in the context of a new Parametric::Mixin, it is possible to work with the parameters in more versitle ways. Here is a simple example that uses a parameter to define a method and another parameter to define it's return value.

module M
  include Paramix::Parametric

  paramaterized do |params|
    define_method params[:name] do
      params[:value]
    end
  end
end

class X
  include M[:name=>'foo', :value='bar']
end

X.new.foo  #=> 'bar'

Copyrights

Copyright (c) 2006 Rubyworks

This program is ditributed unser the terms of the BSD-2-Clause license.

See COPYING.rdoc file for details.

About

Parmetric Mixins

Resources

Stars

25 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages