def_method(mod, methodname, fname='(ERB)') public

Define methodname as instance method of mod from compiled ruby source.

example:

  filename = 'example.rhtml'   # 'arg1' and 'arg2' are used in example.rhtml
  erb = ERB.new(File.read(filename))
  erb.def_method(MyClass, 'render(arg1, arg2)', filename)
  print MyClass.new.render('foo', 123)
Show source
Register or log in to add new notes.