In Files

  • erb.rb

Class/Module Index [+]



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

Public Class Methods

h(s) click to toggle source
Alias for: html_escape
html_escape(s) click to toggle source

A utility method for escaping HTML tag characters in s.

require "erb"
include ERB::Util

puts html_escape("is a > 0 & a < 10?")


is a &gt; 0 &amp; a &lt; 10?
               # File erb.rb, line 826
def html_escape(s)
  s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
Also aliased as: h
u(s) click to toggle source
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")


               # File erb.rb, line 845
def url_encode(s)
  s.to_s.dup.force_encoding("ASCII-8BIT").gsub(/[^a-zA-Z0-9_\-.]/n) {
    sprintf("%%%02X", $&.unpack("C")[0])
Also aliased as: u

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit

blog comments powered by Disqus