From: matz@... (Yukihiro Matsumoto) Date: 2002-11-26T15:26:51+09:00 Subject: Re: each_with_index & collect_with_index? Hi, In message "Re: each_with_index & collect_with_index?" on 02/11/26, Tim Bates writes: |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") I prefer this require 'stringio' s = StringIO.new string.each_with_index do |line, i| s.puts "

#{i} - #{line}" end |However, is seeking completeness such a horrible thing? No. It's not bad. It's not horrible. It's just not a ultimate goal. matz.