module CGI::Escape

def escape(string)

# => "%27Stop%21%27+said+Fred"
url_encoded_string = CGI.escape("'Stop!' said Fred")
Space characters (+" "+) are encoded with plus signs (+"+"+)
URL-encode a string into application/x-www-form-urlencoded.
def escape(string)
  encoding = string.encoding
  buffer = string.b
  buffer.gsub!(/([^ a-zA-Z0-9_.\-~]+)/) do |m|
    '%' + m.unpack('H2' * m.bytesize).join('%').upcase
  end
  buffer.tr!(' ', '+')
  buffer.force_encoding(encoding)
end