From: Bruce Williams Date: 2003-03-28T08:00:29+09:00 Subject: Re: Array question On Thursday 27 March 2003 05:38 pm, Gavin Sinclair wrote: | 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 I think this is an excellent idea and would be a nice addition to Ruby. Please RCR it, if not done already. --- url: http://www.rubygarden.org/index.php?topic=RCR -- - author: Bruce R. Williams url: http://codedbliss.com irc: { nick: iusris, channel: ruby-lang, server: irc.freenode.net } quote: > It does not require a majority to prevail, but rather an irate, tireless minority keen to set brush fires in people's minds. -- Samuel Adams