method

module_exec

v1_8_7_72 - Show latest stable - Class: Module
module_exec(...)
public

Evaluates the given block in the context of the class/module. The method defined in the block will belong to the receiver.

   class Thing
   end
   Thing.class_exec{
     def hello() "Hello there!" end
   }
   puts Thing.new.hello()

produces:

   Hello there!