Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created August 22, 2021 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/4f6d388c17dddf95d7f6ebbae09d0a66 to your computer and use it in GitHub Desktop.
Save kyanny/4f6d388c17dddf95d7f6ebbae09d0a66 to your computer and use it in GitHub Desktop.
require 'uri'
url = 'http://example.com?foo=1&bar=2'
uri = URI.parse(url)
decoded_query = URI.decode_www_form(uri.query)
pp decoded_query, decoded_query.class
decoded_query_hash = Hash[decoded_query]
pp decoded_query_hash, decoded_query_hash.class
@kyanny
Copy link
Author

kyanny commented Aug 22, 2021

❯ ruby uri.rb
[["foo", "1"], ["bar", "2"]]
Array
{"foo"=>"1", "bar"=>"2"}
Hash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment