Skip to content

Instantly share code, notes, and snippets.

@havenwood

havenwood/url.rb Secret

Created September 29, 2012 19:01
Show Gist options
  • Save havenwood/bb3f0dfd24dcbfbf1348 to your computer and use it in GitHub Desktop.
Save havenwood/bb3f0dfd24dcbfbf1348 to your computer and use it in GitHub Desktop.
irc url
>> require 'uri'
=> true
>> url = URI.parse 'http://anyurl.com?value=placeholder'
=> #<URI::HTTP:0x007f9d25694ed8 URL:http://anyurl.com?value=placeholder>
>> url.scheme
=> "http"
>> url.host
=> "anyurl.com"
>> url.query
=> "value=placeholder"
>> new_url = "#{url.scheme}://#{url.host}?#{url.query.sub('placeholder', 'new_value')}"
=> "http://anyurl.com?value=new_value"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment