Skip to content
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
qed
work
.gemspec
.gitignore
.ruby
.travis.yml
.yardopts
Assembly
COPYING.rdoc
Gemfile
HISTORY.rdoc
MANIFEST
PROFILE
QED.rdoc
README.rdoc

README.rdoc

Paramix

Project

Paramix

Copyright

© 2006 Rubyworks

License

BSD-2-Clause

Website

rubyworks.github.com/paramix

Source

github.com/rubyworks/paramix

Status

Description

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

Release Notes

Please see the HISTORY.rdoc file.

Examples

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 © 2006 Thomas Sawyer

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

See COPYING.rdoc file for details.

Something went wrong with that request. Please try again.