Module: ERB::Util (Ruby 2.3.7)
Description: Module : ERB::Util - Ruby 2.3.7

- Home
- Core 2.3.7
- Std-lib 2.3.7
- Downloads

Support for the Ruby 2.3 series has ended. See here for reference.

### Home Classes Methods

### In Files

- erb.rb

### Methods

- ::h
- ::html_escape
- ::u
- ::url_encode

### Class/Module Index

Quicksearch

- ERB
- ERB::DefMethod
- ERB::Util

No matching classes.

# ERB::Util

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?")

Generates

    is a &gt; 0 &amp; a &lt; 10?

                   # File erb.rb, line 944
    def html_escape(s)
      CGI.escapeHTML(s.to_s)
    end

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")

Generates

    Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide

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

Also aliased as: u