ERB.new
# File tmp/rubies/ruby-4.0.0/lib/erb.rb, line 831
def initialize(str, trim_mode: nil, eoutvar: '_erbout')
compiler = make_compiler(trim_mode)
set_eoutvar(compiler, eoutvar)
@src, @encoding, @frozen_string = *compiler.compile(str)
@filename = nil
@lineno = 0
@_init = self.class.singleton_class
end
Returns a new ERB object containing the given string template.
For details about template, its embedded tags, and generated results, see ERB.
Keyword Argument trim_mode
You can use keyword argument trim_mode: '%' to enable the shorthand format for execution tags.
This value allows blank line control:
-
'-': Omit each blank line ending with'%>'.
Other values allow newline control:
-
'>': Omit newline for each line ending with'%>'. -
'<>': Omit newline for each line starting with'<%'and ending with'%>'.
You can also combine trim modes.
Keyword Argument eoutvar
The string value of keyword argument eoutvar specifies the name of the variable that method result uses to construct its result string; see src.
This is useful when you need to run multiple ERB templates through the same binding and/or when you want to control where output ends up.
It’s good practice to choose a variable name that begins with an underscore: '_'.