Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

ERB#def_module

(?::String) -> ::Module
def_module(method_name = 'erb') → new_module

Returns a new nameless module that has instance method method_name.

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