From: "Shot (Piotr Szotkowski)" Date: 2010-02-14T18:03:10+09:00 Subject: Re: Can Ruby Do This? --jI8keyz6grp/JLjh Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Robert Klemme: > On 05.02.2010 06:01, Kirk Haines wrote: >> But, the real answer there is that there's another >> way to do it in Ruby that's substantially faster. >> 0.upto(10000000) {|i| #do whatever you need to do with i } > This one does one iteration more than the original > code if I'm not mistaken. There's also > 10000000.times {|i| #do whatever you need to do with i } A (very) minor nitpick, but =E2=80=93 as this thread will hopefully turn into a newbie magnet =E2=80=93 worth noting that the above are not perfectly equivalent; Integer#upto will go all the way up to 10000000, while Integer#times will iterate 10000000 times (so actually one less). :) > Just as a vague idea: a similar thing could be created with OpenStruct > accesses - saves you a lot of typing of []. Then you could do > hash.foo.bar.baz =3D 123 If the nesting represents any kind of object structure (which in this case it seems to do), I=E2=80=99d actually prefer the OpenStruct solution. =E2=80=94 Shot --=20 There are two hard problems in computer science: cache invalidation, naming things, and off-by-one errors. --jI8keyz6grp/JLjh 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) iEYEARECAAYFAkt3vEkACgkQi/mCfdEo8Uq40wCdEQTldRuqe8iD03PlGIxQcQXJ nV8AoITCvsft8+rNjFQGfe+vnSD4Vj4U =pjNJ -----END PGP SIGNATURE----- --jI8keyz6grp/JLjh--