On Oct 20, 2004, at 11:05 AM, 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 > Here is another solution your probably not interested in: module Enumerable def separate_by(&block) ary = [] each_with_index do |obj, i| ary << block.call if i > 0 ary << obj end ary end end puts [1,2,3].separate_by { "-" }.join("\n") ## output: 1 - 2 - 3 -Charlie