From: Tim Bates Date: 2002-11-26T13:55:29+09:00 Subject: Re: each_with_index & collect_with_index? On Tue, 26 Nov 2002 02:13 pm, Yukihiro Matsumoto wrote: > These ideas are proposed several times. But no one ever succeeded to > persuade me to add these. Do you think of any concrete usage of these > methods, not just for seeking completeness? I gave one example in another thread, which was the example that I ran into that caused me to bring this up in the first place. To take a string, split it into paragraphs, turn each of them into an HTML

and number them: i = 0 string.split("\n").collect{ |s| '

' + (i += 1).to_s + " - " + s }.join("\n") could be better written as: string.split("\n").collect_with_index{ |i, s| '

' + i.to_s + " - " + s }.join("\n") removing the need for the external 'i' variable. However, is seeking completeness such a horrible thing? We have an each_with_index, and the parallels between each and collect are enough that one might expect there to be an equivalent for collect. Tim Bates -- tim@bates.id.au