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')
lib/erb.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/erb.rb, line 957
def def_module(methodname='erb')
mod = Module.new
def_method(mod, methodname, @filename || '(ERB)')
mod
end
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