--cPi+lWm09sJ+d57q
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Daniel Finnie:

> To pass a block as a block to another function,
> put an ampersand before the variable name

Thanks, this works perfectly now:

module Enumerable
  def parallel &block
    case ArtDecomp::Config.processes
    when 1 then map &block
    else forkoff ArtDecomp::Config.processes, &block
    end
  end
end

(I should probably put it in a module and extend the
relevant enums rather than monkeypatching Enumerable=E2=80=A6)

> If you are interested in performance, know that using the &block
> notation for blocks is slower than using the block_given? and yield
> semantics.

Thanks for the tip. In which cases does it matter? (In my very rough
benchmarks it doesn=E2=80=99t, but then the enum in question is rather smal=
l,
while the block=E2=80=99s contents take relatively long time to compute.)

How would I implement the above using block_given? + yield?

Sorry for being braindead here =E2=80=93 I implemented #every_pair by wrapp=
ing
#each twice, but I=E2=80=99m a bit stumbled on how to handle #map=E2=80=99s=
/#forkoff=E2=80=99s
returns; cache them in an array? I tried wrapping my mind around this
but I still don=E2=80=99t feel familiar enough in the block/yield territory=
=E2=80=A6
How would I pass the (variable number of) block=E2=80=99s arguments through
#parallel to the called methods? (I tried to come up with something
using *args but failed.)

-- Shot
--=20
If I had wanted your website to make noise I would have licked
my finger and rubbed it across the monitor.   -- istartedi, /.

--cPi+lWm09sJ+d57q
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFINERQi/mCfdEo8UoRAsEHAJ4vjoMQmCGTx6nPeoEVcmGWB/GFywCgsyHf
TG3IeSB61pIhiwWEVFN10J0=
=Ri3a
-----END PGP SIGNATURE-----

--cPi+lWm09sJ+d57q--