Tom Sawyer <transami / transami.net> 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