From: "Shot (Piotr Szotkowski)" Date: 2008-05-19T05:03:07+09:00 Subject: How to wrap either forkoff or map depending on a config variable? --ee6FjwWxuMujAVRe Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, good people of ruby-talk. I=E2=80=99m trying to write an Enumerable#parallel method that, depending on a config option (retrieved inside it) would end up being an alias for either Enumerable#map or Enumerable#forkoff. (I know calling enum.forkoff(1) should equal enum.map, but I need the wrapper to call #map, as forkoff doesn=E2=80=99t work under JRuby.) I=E2=80=99m quite new to the idea of blocks/closures, and while I love using them, I=E2=80=99m still not sure how to write such a method. What I=E2=80= =99m looking for is something like this: module Enumerable def parallel &block if Config.processes =3D=3D 1 # call map with the passed block else # call forkoff with the passed block end end end Ideally, the call to forkoff would pass Config.processes as its first param =E2=80=93 i.e., calling enum.parallel {=E2=80=A6} would mean ca= lling enum.forkoff(Config.processes) {=E2=80=A6} -- Shot --=20 An Emacs reference mug is what I want. It would hold ten gallons of coffee. -- Steve VanDevender, asr --ee6FjwWxuMujAVRe Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFIMIz3i/mCfdEo8UoRAuXqAKCIuD9sPyFdcr4eERZl49yWnjU6awCdFd9J LgcFNsx7GKr3UpRgr7i140Q= =fr2j -----END PGP SIGNATURE----- --ee6FjwWxuMujAVRe--