From: Michael Neumann Date: 2004-10-21T04:09:36+09:00 Subject: Re: each with separator On Thu, Oct 21, 2004 at 03:54:17AM +0900, Phil Tomson wrote: > In article <20041020180532.GA1126@miya.intranet.ntecs.de>, > Michael Neumann wrote: > >Hi, > > > >I know we had a similar thread in the past about first/last-element > >detection. > > > >In Smalltalk there's #do:separateBy: which basically works like > >each+join combined, but in an imperative fashion. > > > >Now I tried to implement: > > > > [1,2,3].separate_by { puts "-" }.each {|obj| > > puts obj > > } > > > >desired output: > > > > 1 > > - > > 2 > > - > > 3 > > > > Well, it's not exactly the general-purpose solution you're looking for, > but I would do it like this: > > [1,2,3].join("\n-\n").each {|i| puts i } Yes of course, but it's not imperative and I'm looking for an imperative version like the Smalltalk one. Regards, Michael