Skip to content

Instantly share code, notes, and snippets.

@jelder
Created April 3, 2011 17:18
Show Gist options
  • Save jelder/900581 to your computer and use it in GitHub Desktop.
Save jelder/900581 to your computer and use it in GitHub Desktop.
Shortcut for manipulating HTTP request parameters
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