Hash#to_query_string

Update: Rails has a Hash#to_param nowadays.

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