Created
February 10, 2012 10:09
-
-
Save pedromg/1788371 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
query = "param1=1¶m2=2&offset=3" | |
unless query.empty? | |
# build an Hash based on the query string | |
# we want to build {"param1"=>"1", "param2"=>"2", "offset"=>"3"} | |
temp_params = {} | |
query.split("&").each {|v| temp_params.merge!(Hash[*v.split("=")]) unless (v.split("=").count < 2)} | |
# remove the offset parameter | |
temp_params.delete("offset") | |
# convert the Hash back to a String | |
new_query = temp_params.map{|k,v| "#{k}=#{v}"}.join("&") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hum, tens razão, parti do principio que estarias a usar o Rails.