module ERB::Util

A utility module for conversion routines, often handy in HTML generation.

Public Class Methods

h(s)
Alias for: html_escape
html_escape(s) click to toggle source
# File erb.rb, line 1004
def html_escape(s)
  CGI.escapeHTML(s.to_s)
end
Also aliased as: h
u(s)
Alias for: url_encode
url_encode(s) click to toggle source

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

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
# File erb.rb, line 1024
def url_encode(s)
  CGI.escapeURIComponent(s.to_s)
end
Also aliased as: u