Skip to content
class method

ERB.new

(::String, ?eoutvar: ::String, ?trim_mode: ::Integer | ::String | ::NilClass) -> ::ERB
ERB.new(template, trim_mode: nil, eoutvar: '_erbout')

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: '_'.

See also .version #def_class also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0