Modifying URLs

I’d like to be able to take a URL and add or modify a param, just like
url_for does in ActionController.

However, I’d like to be able to do this for a URL taken as a string,
without a controller behind it. So I can’t just call url_for.

Any ideas? What’s the best way to do this?