I would like to take out a parameter from a URL by its name without knowing which parameter it is, and reassemble the URL again.
I guess it is not that hard to write something on my own using CGI or URI, but I imagine such functionality exists already. Any suggestions?
In:
http://example.com/path?param1=one¶m2=2¶m3=something3
Out:
http://example.com/path?param2=2¶m3=something3
The addressable gem will do this nicely; please see the superior answer by The Tin Man. But if you want to roll your own, here’s how. The only claim this code has to elegance is that it hides the ugly in a method: