URL encoding with Ruby

URL encoding with Ruby Image

Published Date: September 9, 2022

Updated Date: September 9, 2022

In order to encode a string or a URL in Ruby, you can use the CGI::Escape method. This method will escape or encode the string or URL in Ruby.

How to encode a string or a URL in RUBY

require 'cgi'

url_encoded_string = CGI.escape("Enc@de my Str!ng in @Ruby")

puts url_encoded_string


# Output

Related Encoding techniques:

There are many applications that require you to encode your URL into a format that the systems can understand. If you wish to encode a URL, check out our free online URL Encoder.

Some systems communicate with encoded URLs, so you may need to decode a URL. If you want to decode a URL online, we have our free online URL Decoder.