def_method(mod, methodname, fname='(ERB)')
public
Define methodname as instance method of mod from compiled
Ruby source.
example:
filename = 'example.rhtml'
erb = ERB.new(File.read(filename))
erb.def_method(MyClass, 'render(arg1, arg2)', filename)
print MyClass.new.render('foo', 123)
Show source
def def_method(mod, methodname, fname='(ERB)')
src = self.src
magic_comment = "#coding:#{@enc}\n"
mod.module_eval do
eval(magic_comment + "def #{methodname}\n" + src + "\nend\n", binding, fname, -2)
end
end