Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

CGI::Escape#escape_uri_component

(::string) -> ::String
escape_uri_component(string)

Alias of #escapeURIComponent

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

Example
url_encoded_string = CGI.escapeURIComponent("'Stop!' said Fred")
   # => "%27Stop%21%27%20said%20Fred"