From: Jason Creighton Date: 2003-06-11T13:28:53+09:00 Subject: Re: [RCR] join block On Tue, 10 Jun 2003 01:40:26 +0200 "Simon Strandgaard" <0bz63fz3m1qt3001@sneakemail.com> wrote: > On Mon, 09 Jun 2003 16:01:39 +0000, Jason Creighton wrote: > > > > It seems having #join take a block might be easier sometimes. And isn't > > Ruby about making programming easy? > > This is what its all about :-) > > > Another example where 'collect-join' could be useful > > > I have such pieces of code everywhere in my code in order to debug. > def debug > $log.puts "XXX "+data.join("\nXXX ") > end > > But it duplicates "XXX ".. not nice. > I could do like this, but I think its unnecessary complicated > def debug > $log.puts data.collect {|d| "XXX #{d}\n"}.join > end > > > It could be written really nice using 'collect-join' > def debug > $log.puts data.join {|d| "XXX #{d}\n"} > end I have yet to be overcome with the ugliness of the second method. :-) Also, I agree with "daz" that this could be solved easier other ways: def debug data.each { |d| $log.print "XXX #{d}\n" } end IMO, clearer, because it does exactly what your code (appears to me) to be doing: Print an array (Actually, any object that supports Enumerable) one element per line, prefixed with "XXX ". However, the fact that this one example could be done differently does not invalidate the idea of #join accepting a block. I just don't see a huge need for this. But you obviously do, and others might as well, so maybe stuff like this should be implemented in the way I suggested in my earlier post: a "require 'array/joinblock'" for little convience features like this, and don't bother to implement them in C. Jason Creighton