C
Csaba Henk
Hi list, group,
I'm glad to announce:
Multiblocks
===========
A framework for defining callgroups, that is, a group of methods which
behave in a somewhat Smalltalkish way, ie. they appear to be one method
which can take multiple blocks.
Location
--------
The homepage is
http://www.creo.hu/~csaba/ruby/multiblocks/
There is also a Rubyforge project page:
http://rubyforge.org/projects/multiblocks/
Distributed as gem, zip, and tarball (a quick link to this):
http://www.creo.hu/~csaba/ruby/multiblocks/download/multiblocks-0.1.0.tar.gz
under the Ruby License.
Example
-------
In following example a callgroup will be created, where the calls in the
group take keys and blocks, and upon execution, the blocks are called in
order according to the keys.
class PermuteBlocks
callgroup
do,:&)
def sanitizer
@grpargv[-1][1].size == 1 and @grpargv[-1][2]
end
grp_finalizer :end do
@grpargv.sort_by {|a| a[1]}.each {|a| a[2][] }
end
end
PermuteBlocks.new.do(2){puts "a"}.&(1){puts "b"}.&(3){puts "c"}.end
p PermuteBlocks.callgroups
produces:
b
a
c
{
grpargv=>{:calls=>[:do, :&], :sanitizer=>:sanitizer, :finalizers=>[:end]}}
It can be also useful if one needs keyword arguments with reflection.
That is, instead of writing something like
Server.start
port => 1234, :dir => "/tmp/foo", :user => "nobody")
one could write
Server.port(1234).dir("/tmp/foo").user("nobody").start
Further features
--------
* thread safe
* provides a clean and simple way for structuring arguments of
complex method calls
Documentation
-------------
Rdoc. Online version at
http://www.creo.hu/~csaba/ruby/multiblocks/rdoc
Csaba
I'm glad to announce:
Multiblocks
===========
A framework for defining callgroups, that is, a group of methods which
behave in a somewhat Smalltalkish way, ie. they appear to be one method
which can take multiple blocks.
Location
--------
The homepage is
http://www.creo.hu/~csaba/ruby/multiblocks/
There is also a Rubyforge project page:
http://rubyforge.org/projects/multiblocks/
Distributed as gem, zip, and tarball (a quick link to this):
http://www.creo.hu/~csaba/ruby/multiblocks/download/multiblocks-0.1.0.tar.gz
under the Ruby License.
Example
-------
In following example a callgroup will be created, where the calls in the
group take keys and blocks, and upon execution, the blocks are called in
order according to the keys.
class PermuteBlocks
callgroup
def sanitizer
@grpargv[-1][1].size == 1 and @grpargv[-1][2]
end
grp_finalizer :end do
@grpargv.sort_by {|a| a[1]}.each {|a| a[2][] }
end
end
PermuteBlocks.new.do(2){puts "a"}.&(1){puts "b"}.&(3){puts "c"}.end
p PermuteBlocks.callgroups
produces:
b
a
c
{
It can be also useful if one needs keyword arguments with reflection.
That is, instead of writing something like
Server.start
one could write
Server.port(1234).dir("/tmp/foo").user("nobody").start
Further features
--------
* thread safe
* provides a clean and simple way for structuring arguments of
complex method calls
Documentation
-------------
Rdoc. Online version at
http://www.creo.hu/~csaba/ruby/multiblocks/rdoc
Csaba