Skip to content

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

instance method

ERB::Util#url_encode

url_encode(s)

A utility method for encoding the String s as a URL.

Example
require "erb"
include ERB::Util

puts url_encode("Programming Ruby:  The Pragmatic Programmer's Guide")

Generates

Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
See also .url_encode #u #html_escape also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0