From: Robert Klemme Date: 2006-12-06T21:45:06+09:00 Subject: Re: join_with On 06.12.2006 11:40, Martin DeMello wrote: > While golfing with the hex_ip thread, I realised that map takes no > argument, and join takes no block, leaving a vacuum for a combined > method: > > module Enumerable > def join_with(sep, &blk) > map(&blk).join(sep) > end > end > > hex_ip.scan(/../).join_with('.') {|i| i.hex} > > join_with is still a little clunky - any better name? Hm. I am not convinced this is a good idea at all. Usually the recommendation is that methods should do one thing - and one thing only. Combining map with join seems like a clear violation of that principle as map and join do extremely different things. Having said that I'd prefer a more efficient implementation: module Enumerable def jw( sep ) first = true inject("") do |s, x| if first first = false else s << sep end s << yield( x ) end end end Kind regards robert