From: "Shot (Piotr Szotkowski)" Date: 2009-09-26T02:36:19+09:00 Subject: Backporting Enumerator.new { ... } to Ruby 1.8.7 --vtzGhvizbBRQ85DL 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 backport my code from Ruby 1.9 to Ruby 1.8.7 so that = I can profile it sanely with ruby-prof or zenprofile (neither of which works sensibly under Ruby 1.9 as of now). Unfortunately, my code heavily uses lazy-evaluated, nested Enumerator objects. What is the sanest way to backport the following example so that it works more-or-less in the same way under Ruby 1.8.7 as it does under Ruby 1.9? def multiplier param Enumerator.new do |yielder| (1..10).each do |elem| sleep 1 # simulates a long-running process yielder.yield param * elem end end end multiplier(3).each do |e| puts e end I think I need a proxy object that can emulate Ruby 1.9=E2=80=99s Enumerato= r.new by taking a block and then being able to evaluate it in the original calling place=E2=80=99s context (so that the =E2=80=98param=E2=80=99 above = is available to it upon subsequent Enumerator#each calls), but my still-limited Ruby-fu fails to come up with a solution for this. =E2=80=94 Shot --=20 Local Man Plans To Run 3 Weeks=E2=80=99 Worth of Errands During Twitter Maintenance Window [Patently False] --vtzGhvizbBRQ85DL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkq8/44ACgkQi/mCfdEo8UpBMQCfe57iT2dWKim5Ro6M07CV5xzz 6RcAoLicxPlSa4KDPBJpkR2DRuS8xJ8V =9z+T -----END PGP SIGNATURE----- --vtzGhvizbBRQ85DL--