Skip to content
instance method

ERB#def_method

(::Module, ::String, ?::String) -> untyped
def_method(module, method_signature, filename = '(ERB)') → method_name

Creates and returns a new instance method in the given module module; returns the method name as a symbol.

The method is created from the given method_signature, which consists of the method name and its argument names (if any).

The filename sets the value of filename; see Error Reporting.

Example
template = '<%= arg1 %> <%= arg2 %>'
erb = ERB.new(template)
MyModule = Module.new
erb.def_method(MyModule, 'render(arg1, arg2)') # => :render
class MyClass; include MyModule; end
MyClass.new.render('foo', 123)                      # => "foo 123"
See also #def_class #def_module .version #location= also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0