title: convert ruby hash to URL query string ... without those square brackets
body: <p>In Python, I can do this:</p>
  
  <pre><code>&gt;&gt;&gt; import urlparse, urllib
  &gt;&gt;&gt; q = urlparse.parse_qsl("a=b&amp;a=c&amp;d=e")
  &gt;&gt;&gt; urllib.urlencode(q)
  'a=b&amp;a=c&amp;d=e'
  </code></pre>
  
  <p>In Ruby[+Rails] I can't figure out how to do the same thing without "rolling my own," which seems odd. The Rails way doesn't work for me -- it adds square brackets to the names of the query parameters, which the server on the other end may or may not support:</p>
  
  <pre><code>&gt;&gt; q = CGI.parse("a=b&amp;a=c&amp;d=e")
  =&gt; {"a"=&gt;["b", "c"], "d"=&gt;["e"]}
  &gt;&gt; q.to_params
  =&gt; "a[]=b&amp;a[]=c&amp;d[]=e"
  </code></pre>
  
  <p>My use case is simply that I wish to muck with the values of some of the values in the <code>query-string</code> portion of the URL. It seemed natural to lean on the standard library and/or Rails, and write something like this:</p>
  
  <pre><code>uri = URI.parse("http://example.com/foo?a=b&amp;a=c&amp;d=e")
  q = CGI.parse(uri.query)
  q.delete("d")
  q["a"] &lt;&lt; "d"
  uri.query = q.to_params # should be to_param or to_query instead?
  puts Net::HTTP.get_response(uri)
  </code></pre>
  
  <p>but only if the resulting URI is in fact <code>http://example.com/foo?a=b&amp;a=c&amp;a=d</code>, and not <code>http://example.com/foo?a[]=b&amp;a[]=c&amp;a[]=d</code>. Is there a correct or better way to do this?</p>