Hash#to_query_string

I’d love to see something like this somewhere in the 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

Note

Don’t forget about ERB::Util.h for your HTML-escaping needs.