From: Tom Sawyer Date: 2002-07-12T04:22:02+09:00 Subject: Re: spliter of for...each: looping > Seems a little cleaner/clearer, but that's IMHO of course :) Your > method is probably more efficient, since the one I mentioned creates > an intermediate array. I guess it depends on how performance critical > the code in question is. actually joins faster. just tested it out. also discovered that: "junk#{x}morejunk" is much faster then "junk" << x << "morejunk" thanks for all the help guys! i think i can speed up miter a bit just by using join. ~transmi On Thu, 2002-07-11 at 09:50, Josh Huber wrote: > Tom Sawyer writes: > > > what i now do: > > q = '' > > arr.each_with_nindex do |x, n| > > q << 'junk' << x << 'morejunk' > > q << ',' if n != -1 > > end > > > > how do you do it with join? > > > > note: how i used to do it is probably a tad faster actually > > Hmm, how about something like... > > arr.collect { |x| 'junk' + x + 'morejunk' }.join(",") > > ? > > Seems a little cleaner/clearer, but that's IMHO of course :) Your > method is probably more efficient, since the one I mentioned creates > an intermediate array. I guess it depends on how performance critical > the code in question is. > > -- > Josh Huber > -- ~transami "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -- Benjamin Franklin