module ERB::Util
A utility module for conversion routines, often handy in HTML generation.
Public Class Methods
h(s)
Alias for: html_escape
# File lib/erb.rb, line 1001 def html_escape(s) CGI.escapeHTML(s.to_s) end
A utility method for escaping HTML tag characters in s.
require "erb" include ERB::Util puts html_escape("is a > 0 & a < 10?")
Generates
is a > 0 & a < 10?
Also aliased as: h
u(s)
Alias for: url_encode
# File 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.
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
Also aliased as: u
Private Instance Methods
h(s)
Alias for: html_escape
# File lib/erb.rb, line 1001 def html_escape(s) CGI.escapeHTML(s.to_s) end
A utility method for escaping HTML tag characters in s.
require "erb" include ERB::Util puts html_escape("is a > 0 & a < 10?")
Generates
is a > 0 & a < 10?
Also aliased as: h
u(s)
Alias for: url_encode
# File 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.
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
Also aliased as: u
Ruby Core © 1993–2020 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.