From: Farrel Lifson Date: 2007-02-28T14:36:33+09:00 Subject: Re: Potential RCR?: Array#join with block On 28/02/07, Austin Ziegler wrote: > On 2/27/07, Farrel Lifson wrote: > > Does anyone think Array#join with a block is a potential RCR? > > [1,3,2,4].join("-"){|sep,a,b| sep + (a > b ? ">" : "<")} > > which would produce > > "1-<3->2-<4" > > > I thought it would be nice to make the join string a bit more dynamic. > > > > I've got working C code which I'm just testing/optimising further at > > the moment. Is it worthy of submission as an RCR to trunk? > > I'd dig through the archives; I'm pretty sure that Matz has weighed in > on this in the past; I don't think it's a good idea, myself. > > -austin > -- > Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ > * austin@halostatue.ca * http://www.halostatue.ca/feed/ > * austin@zieglers.ca > > I've had a look and found two threads so far (http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/8d1e99cf3e98215/beb0827ac4801573?lnk=gst&q=join+with+block&rnum=1#beb0827ac4801573, http://groups.google.com/group/ruby-talk-google/browse_thread/thread/5f75c7d3edf7e5d0/a33056d675a18727?q=join+with+block&lnk=ol&) but neither seems to come to a hard and fast conclusion. Some people like it and some don't. One thing that seems different in my implementation is I pass in the initial separator string as well as the two elements it will be placed between to the block. Calling join without the block still works exactly the same as the current version. Farrel