From: Eero Saynatkari Date: 2005-11-09T04:00:00+09:00 Subject: Re: Better way to build string marcus wrote: > I'm trying to build a query string based on an array of properties. Is > there a shorter/nicer way to do the following? > > def build_query_string(properties, prop_type) > result = "" > > properties.each do |item| > if prop_type == "tag" > result += " #{item.name}=#{item.value}" > else > if result == "" > result = "?" > else > result += "&" > end > result += "#{item.name}=#{item.value}" > end > end > > result > end Perhaps you can modify this for your needs: properties.inject('?') {|memo, (key, value)| memo << "#{key}=#{value}&" } > /Marcus E