Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

ERB#def_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.4 · 3.3 · 3.2 · 3.0