Created
April 3, 2011 17:18
-
-
Save jelder/900581 to your computer and use it in GitHub Desktop.
Shortcut for manipulating HTTP request parameters
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
class ParamHash < HashWithIndifferentAccess | |
def merge_string!(string) | |
hash = Hash.new | |
string.split('&').each { |kv| | |
k,v = kv.split('=') | |
hash[k] = URI::unescape(v) | |
} | |
self.merge! hash | |
end | |
def merge_string(string) | |
hash = Hash.new | |
string.split('&').each { |kv| | |
k,v = kv.split('=') | |
hash[k] = URI::unescape(v) | |
} | |
self.merge hash | |
end | |
def to_s | |
self.map { |k,v| "#{k}=#{ URI::escape(v.to_s) }" }.join('&') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment