Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

ERB::Util.html_escape

html_escape(s)

A utility method for escaping HTML tag characters in s.

Example
require "erb"
include ERB::Util

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

Generates

is a &gt; 0 &amp; a &lt; 10?
See also #html_escape .h .u .url_encode also in 3.0