On Apr 16, 1:10 pm, "ara.t.howard" <ara.t.how... / gmail.com> wrote:
> On Apr 15, 2008, at 9:35 PM, Fredrik wrote:
>
> > But there isn't, right?
>
> cfp:~ > cat a.rb
> module Enumerable
>    def forkify &b
>      map do |*a|
>        r, w = IO.pipe
>        fork do
>          r.close
>          w.write( Marshal.dump( b.call(*a) ) )
>        end
>        [ w.close, r ].last
>      end.map{|r| Marshal.load [ r.read, r.close ].first}
>    end
> end
>
> result =
>    [0, 1, 2, 3].forkify do |i|
>      p [ Process.ppid, Process.pid ]
>      i ** 2
>    end
>
> p result
>
> cfp:~ > ruby a.rb
> [80870, 80871]
> [80870, 80872]
> [80870, 80873]
> [80870, 80874]
> [0, 1, 4, 9]
>
> a @http://codeforpeople.com/
> --
> we can deny everything, except that we have the possibility of being
> better. simply reflect on that.
> h.h. the 14th dalai lama

Thanks! This code is just what I am looking for!
Peach for JRuby seems nice too, but I don't have JRuby :)