I’d love to see something like this somewhere in the Ruby standard library:
require "erb"
class Hash
def to_query_string
u = ERB::Util.method(:u)
map { |k, v|
u.call(k) + "=" + u.call(v)
}.join("&")
end
end
Don’t forget about ERB::Util.h for your HTML-escaping needs.