I made a small utility library named
Wormhole.
The library enables us to communicat
Here is a simple example of use.
1 require 'rubygems' 2 require 'wormhole' 3 4 def foo(array) 5 array << :foo # (1) 6 Wormhole.throw array 7 array << :baz # (3) 8 end 9 10 result = Wormhole.catch do 11 foo [] 12 end.return do |array| 13 array << :bar # (2) 14 end 15 puts result.inspect # => [:foo, :bar, :baz]
First, the block passed to Wormhole.c
By using this utility, you can participat
At the end, you can install this utility from the GitHub by using gem command like this.
1 % sudo gem sources -a http://gems.github.c om 2 % sudo gem install genki-worm hole
Have fun!
posted by
takiuchi
on Sat 5 Jul 2008
at 01:53
with
2 comments
What is the advantage over a regular 'yield', like this?
Suppose there is a black box system between your codes, like this:
caller -> blackbox -> callee
The wormhole enable us to pass anything through the black box to callee from caller without any modifications to the black box.
Vice-versa.
caller <- blackbox <- callee
For example, the black box tends to be a framework such as Ruby on Rails, the callee is a callback and the caller is your application code.