Module: ERB::Util

Module | ERB::Util
In: | erb.rb

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

### Methods

h html_escape u url_encode

### Public Instance methods

h(s)

Alias for html_escape

html_escape(s)

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 &gt; 0 &amp; a &lt; 10?

[Source]

    # File erb.rb, line 780
        def html_escape(s)
          s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
        end

u(s)

Alias for url_encode

url_encode(s)

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

[Source]

    # File erb.rb, line 799
        def url_encode(s)
          s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
        end

[Validate]