From: "Shot (Piotr Szotkowski)" Date: 2009-10-10T09:28:19+09:00 Subject: Re: Backporting Enumerator.new { ... } to Ruby 1.8.7 --Fig2xvG2VGoz8o/s Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable James Edward Gray II: > Shot (Piotr Szotkowski) wrote: >>>> 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| > require "generator" [=E2=80=A6] > Or with a closure: [=E2=80=A6] > Or with an object: [=E2=80=A6] > I forgot to mention, there are some > other good resources for code like this: > http://moonbase.rydia.net/software/lazy.rb/ > http://blog.grayproductions.net/articles/infinite_streams Thanks a lot, James! As I just wrote in the reply to Roger Pack, I ended up using the backports gem, and if I didn=E2=80=99t know about it I=E2=80=99d most probably expose Generator.new as Enumerator.new, but the closure and object examples are very enlightening. Even more so is your =E2=80=98Higher-Order Ruby=E2=80=99 series, which I al= ways split into the =E2=80=98understandable=E2=80=99 part on Iterators, Caching and Me= moization, and the =E2=80=98still a bit over my head=E2=80=99 rest. I think I=E2=80=99m finally ready to dive deep and wrap my head around all of the concepts mentioned there. :) =E2=80=94 Shot --=20 Blore=E2=80=99s Razor: Given a choice between two theories, take the one which is funnier. --Fig2xvG2VGoz8o/s 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) iEYEARECAAYFAkrP1R4ACgkQi/mCfdEo8UqUJgCfZERbprDVPUqo88BNbNvQ1j9M duoAn39OoVFXKyKEP1rKqrw64QYsjukG =m3DH -----END PGP SIGNATURE----- --Fig2xvG2VGoz8o/s--