From: Robert Klemme Date: 2013-01-04T06:35:53+09:00 Subject: Re: Block given to Array::join On Thu, Jan 3, 2013 at 9:37 PM, Salvatore nashcrash wrote: > Hi. > I'm a newby in this Forum and in Ruby, but I want give my contribution. > > class Array > alias oldJoin join > def join(sep='') > res=self > res=self.map {|el| yield el} if block_given? > res.oldJoin(sep) > end > end > > What you things about-it? I am thinking that this version is in no way better than using #map and #join explicitly. If you want to make this more efficient, you'd at least have to do something like this class Array def join(sep = '', &b) b ||= lambda {|x| x} s = nil each do |e| if s s << sep else s = '' end << (b[e].to_s) end s end end I am not sure though that this is such a great idea because you can usually do this via #inject. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/