https://github.com/rubyworks/paramix
Parmetric Mixins
https://github.com/rubyworks/paramix
Last synced: 8 months ago
JSON representation
Parmetric Mixins
- Host: GitHub
- URL: https://github.com/rubyworks/paramix
- Owner: rubyworks
- License: other
- Created: 2009-09-09T00:01:03.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2015-04-01T23:11:07.000Z (almost 11 years ago)
- Last Synced: 2024-11-30T14:17:49.899Z (about 1 year ago)
- Language: Ruby
- Homepage: http://rubyworks.github.com/paramix/
- Size: 607 KB
- Stars: 25
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Paramix
[](http://badge.fury.io/rb/paramix)
[](http://travis-ci.org/rubyworks/paramix)
[](http://flattr.com/thing/324911/Rubyworks-Ruby-Development-Fund)
[Website](http://rubyworks.github.com/paramix) ·
[YARD API](http://rubydoc.info/gems/paramix) ·
[Report Issue](http://github.com/rubyworks/paramix/issues) ·
[Source Code](http://github.com/rubyworks/paramix)
## 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.