require 'uri'
uri = URI.parse("http://www.youtube.com/watch?v=og9B3BEnBHo")
uri.query = [uri.query, "wmode=opaque"].compact.join('&')
puts uri.to_s
#edit Since 1.9.2 there are methods added to the URI module
uri = URI.parse("http://www.youtube.com/watch?v=og9B3BEnBHo")
new_query_ar = URI.decode_www_form(String(uri.query)) << ["wmode", "opaque"]
uri.query = URI.encode_www_form(new_query_ar)
puts uri.to_s
(The call to String
ensures that this also works in the case when the original URI does not have a query string)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…