Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

ERB#def_module

(?::String) -> ::Module
def_module(methodname='erb')

Create unnamed module, define methodname as instance method of it, and return it.

example:

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
See also #def_method #location= #def_class #make_compiler also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0