From: William James Date: 2005-02-14T06:44:56+09:00 Subject: Re: "Joining" strings which may be nil (or) Handling Option hashes Robert Klemme wrote: > > Here's a more efficient variant - using #inject of course :-) > > >> opts.inject(nil){|s,(k,v)| v ? (s ? s << " and " : "") << k << "=" << v : > >> s} > => "title=ruby and author=dave and publisher=oreilly" I prefer this: opts.to_a.map{|x| x.join('=') if x[1]}.compact.join(' and ') ----> "title=ruby and author=dave and publisher=oreilly"