From: Martin DeMello Date: 2003-06-09T18:19:09+09:00 Subject: Re: [RCR] join block Simon Strandgaard <0bz63fz3m1qt3001@sneakemail.com> wrote: > > So far I cannot think of any cases where I need to "join-pairs into a > string". Can you show some more examples in order to convince me, that this > actualy is usable ? :-) "{" << [1,2,3,"a","b",5,"c"].join {|x,y| (x.type == y.type) ? "," : "} {" << "}" #=> {1,2,3} {a,b} {5} {c} words.join {|x,y| (x[-1] == ?.) ? "\n" : " "} Even more useful, once we toss in the idea of a block, might be a join_with_index: [1,2,3,4,5,6,7,8,9].join_with_index {|x,y,i| (i % 3 == 2) ? "\n" : " "} 1 2 3 4 5 6 7 8 9 Though it'd be slightly confusing as to whether i referred to the index of x or of y. As for the block working on individual elements, that's map's job. martin