From: Gavin Sinclair Date: 2003-03-28T07:38:25+09:00 Subject: Re: Array question On Friday, March 28, 2003, 9:31:47 AM, walter wrote: > Any one know why Array.join can't take a code block and join that > value instead of what is actually in the array? Perhaps I want to > join on a subfield or process the item before joining it. Right now > I use collect and then join, but that just seems wasteful of memory. > for instance (and yes I know it is a silly example): > list = ["A", "B", "C"] > #I want to do this > puts list.join(","){|item| item.downcase} > #but I have to do this > puts list.collect{|item| item.downcase}.join(",") > Am I missing something? No, that appears to be a very sensible solution to me. It communicates your intentions exactly. If you are working on a very large array, then perhaps you might need to find a way to conserve memory, but it shouldn't be necessary in 99% of cases: the memory used by #collect is very temporary and will be garbage collected. That said, the usage of #join you propose doesn't sound too bad at all. Gavin