A utility module for conversion routines, often handy in HTML generation.
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?
# File erb.rb, line 930
def html_escape(s)
CGI.escapeHTML(s.to_s)
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
# File erb.rb, line 949
def url_encode(s)
s.to_s.dup.force_encoding("ASCII-8BIT").gsub(/[^a-zA-Z0-9_\-.]/) {
sprintf("%%%02X", $&.unpack("C")[0])
}
end
Commenting is here to help enhance the documentation. For example, sample code, or clarification of the documentation.
If you are posting code samples in your comments, please wrap them in "<pre><code class="ruby" > ... </code></pre>" markup in order to get syntax highlighting.
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 a bug report so that it can be corrected for the next release. Thank you.