Created
March 10, 2011 19:20
-
-
Save deyvin/864711 to your computer and use it in GitHub Desktop.
How to Convert Hash to Url Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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