Skip to content

Instantly share code, notes, and snippets.

@deyvin
Created March 10, 2011 19:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deyvin/864711 to your computer and use it in GitHub Desktop.
Save deyvin/864711 to your computer and use it in GitHub Desktop.
How to Convert Hash to Url Query
require "addressable/uri"
class Hash
def to_url_params
uri = Addressable::URI.new
keys.size.times do |i|
self[keys[i]] = "#{values[i].to_s}"
end
uri.query_values = self
uri.query
end
end
my_hash = {:a => "Hello", :b => "World"}
p my_hash.to_url_params
#"a=Hello&b=World"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment