From: Logan Capaldo Date: 2006-12-07T09:14:34+09:00 Subject: Re: join_with On Thu, Dec 07, 2006 at 03:12:23AM +0900, Martin DeMello wrote: > On 12/6/06, Logan Capaldo wrote: > >> > >> hex_ip.scan(/../).join_with('.') {|i| i.hex} > > hex_ip.scan(/../).map {|i| i.hex}.join('.') > >Hey look, the long way is even shorter! Do you just want to conflate > > I knew someone would say that :) > > >these two because theres room in the interface? That seems like a silly > >reason. It would also set a bad precendent. (Well hey, delete doesn't > >take a block, lets add one and pass the deleted item in...) > > No, more because map-then-join is a very common pattern, and the > complementary argument lists let us combine them neatly. > > html_table = ary.jmap("\n") {|col| > col.jmap {|cell| "#{cell}"} > } > > as opposed to > > html_table = ary.map {|col| > col.jmap {|cell| "#{cell}"}.join > }.join("\n") > > The benefit is that the block is the last argument to what is > conceptually a single operation. > I don't see it personally. As far as I am concerned it's two operations. At least it wasn't just "Hey, theres room for this, why not put it in." As for the method name, considered just adding a block to join? array.join("\n") # Normal join array.join("\n") { |item| "#{item}" } Of course theres everybodies favorite iterator: array.inject("") { |s, cell| "#{s}#{cell}\n" } > martin