End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
ERB::Util.url_encode
url_encode(s)
lib/erb.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/erb.rb, line 1020
def url_encode(s)
s.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m|
sprintf("%%%02X", m.unpack1("C"))
}
end
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