From: Tom Robinson Date: 2002-03-29T20:52:36+09:00 Subject: Array#join accept a codeblock? Is there some way to do something like Array#join that takes a codeblock to tell it what to join up the array with? Something like... ary = [1,2,3,4,5] str = ary.myjoin { |idx| if idx == 1 ' ** ' else ' -- ' end } gives str as "1 -- 2 ** 3 -- 4 -- 5" I have written something like this below, but I was wondering if there's anything like this in ruby, or if not maybe it could be added to the next version. :) class Array def myjoin outstr = "" self.each_index { |idx| if idx == self.length - 1 outstr += self[idx].to_s else outstr += self[idx].to_s + yield(idx).to_s end } return outstr end end I'm new to ruby so critiques on this code would be useful.