Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

CGI::Util#escapeURIComponent

escapeURIComponent(string)

URL-encode a string following RFC 3986 Space characters (+“ ”+) are encoded with (+“%20”+)

Example
url_encoded_string = CGI.escape("'Stop!' said Fred")
   # => "%27Stop%21%27%20said%20Fred"
See also #escapeHTML #h #escape_html #pretty also in 3.4 · 3.3 · 3.1