set_eoutvar

set_eoutvar(compiler, eoutvar = '_erbout') Instance Public methods Can be used to set eoutvar as described in ::new. It's probably easier to just use the constructor though, since calling this method requires the setup of an ERB compiler object.

run

run(b=new_toplevel) Instance Public methods Generate results and print them. (see #result)

result

result(b=new_toplevel) Instance Public methods Executes the generated ERB code to produce a completed template, returning the results of that code. (See ::new for details on how this process can be affected by safe_level.) b accepts a Binding object which is used to set the context of code evaluation.

make_compiler

make_compiler(trim_mode) Instance Public methods Creates a new compiler for ERB. See ERB::Compiler.new for details

def_module

def_module(methodname='erb') Instance Public methods Create unnamed module, define methodname as instance method of it, and return it. example: filename = 'example.rhtml' # 'arg1' and 'arg2' are used in example.rhtml erb = ERB.new(File.read(filename)) erb.filename = filename MyModule = erb.def_module('render(arg1, arg2)') class MyClass include MyModule end

def_method

def_method(mod, methodname, fname='(ERB)') Instance Public methods Define methodname as instance method of mod from compiled ruby source. example: filename = 'example.rhtml' # 'arg1' and 'arg2' are used in example.rhtml erb = ERB.new(File.read(filename)) erb.def_method(MyClass, 'render(arg1, arg2)', filename) print MyClass.new.render('foo', 123)

def_class

def_class(superklass=Object, methodname='result') Instance Public methods Define unnamed class which has methodname as instance method, and return it. example: class MyClass_ def initialize(arg1, arg2) @arg1 = arg1; @arg2 = arg2 end end filename = 'example.rhtml' # @arg1 and @arg2 are used in example.rhtml erb = ERB.new(File.read(filename)) erb.filename = filename MyClass = erb.def_class(MyClass_, 'render()') print MyClass.new('foo', 123).render()

version

version() Class Public methods Returns revision information for the erb.rb module.

new

new(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout') Class Public methods Constructs a new ERB object with the template specified in str. An ERB object works by building a chunk of Ruby code that will output the completed template when run. If safe_level is set to a non-nil value, ERB code will be run in a separate thread with $SAFE set to the provided level. If trim_mode is passed a String containing one or more of the following modifiers, ERB will adjust its code generation

url_encode

url_encode(s) Class Public methods 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 u