title: How to change URL parameters through a loop using Ruby?
body: <p>I am trying to change each parameter of this <a href="http://www.exampleofurl.com/search?q=4&amp;e=25;i=8&amp;b=2" rel="nofollow">http://www.exampleofurl.com/search?q=4&amp;e=25;i=8&amp;b=2</a> through a loop, but I am getting this output.</p>
  
  <pre><code>http://www.exampleofurl.com/search?q=changed&amp;e=25;i=8&amp;b=2
  http://www.exampleofurl.com/search?q=4&amp;e=changed;i=8&amp;b=2
  http://www.exampleofurl.com/search?q=4&amp;e=25;i=changed&amp;b=2
  http://www.exampleofurl.com/search?q=4&amp;e=changed5;i=8&amp;b=changed
  </code></pre>
  
  <p>When my parameters are empty, I get this weird output.</p>
  
  <pre><code>search?changedqchanged=changed4changed&amp;changedechanged=changed2changed5changed;changedichanged=changed8changed&amp;changedbchangedochangedochanged=changed
  </code></pre>
  
  <p>Here is my code.</p>
  
  <pre><code>require 'uri'
  url = "http://www.exampleofurl.com/search?q=4&amp;e=25;i=8&amp;b=2"
  uri = URI.parse(url)
  
  params = {}
  t = "changed"
  
  q = uri.query
  p = q.split(/[&amp;;]/) if q != nil
  
  p.each do |part|
     k,v = part.split('=', 2)
     params[k] = v
  
     t.each do |tr|
         uri.query = q.gsub(params[k], tr)
     end
  end
  </code></pre>
  
  <p>Can someone tell me what is wrong and what is the most efficient way to do it?</p>
  
  <p>I want an output like this.</p>
  
  <pre><code>q=changed&amp;e=25;i=8&amp;b=2
  q=4&amp;e=changed;i=8&amp;b=2
  q=4&amp;e=25;i=changed&amp;b=2
  q=4&amp;e=25;i=8&amp;b=changed
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p>Marco</p>