From: "Joe Wölfel" Date: 2008-09-21T08:08:08+09:00 Subject: Re: for or each? Philip, I hadn't thought about your refactoring arguments. I think I'm swayed by them. I do change an each to a map, etc., on occasion. Also, it seems simpler and less confusing to have one simple grammatical construction that does so many things. On 20 sept. 08, at 18:52, Phlip wrote: > Joe Wölfel wrote: > >> You can try my test if you like. I haven't checked it >> carefully. But it does seem like 'each' is much faster under >> both ruby 1.86 and ruby 1.9. The code is below. > > I just experimented with 'for' and found it does not reevaluate its > header each time it runs. That's the only thing that could have > explained the time difference, so maybe Matz & Co. have simply > neglected 'for' while optimizing .each, which everyone uses. > (Though it's still technically superior; not just an /ad populum/ > thing...) > > Another reason to use .each is your collection-like class might > override it to do something cool... >