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!
Show source
/*
* call-seq:
* mod.module_exec(arg...) {|var...| block } => obj
* mod.class_exec(arg...) {|var...| block } => obj
*
* 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()
*
* <em>produces:</em>
*
* Hello there!
*/
VALUE
rb_mod_module_exec(argc, argv, mod)
int argc;
VALUE *argv;
VALUE mod;
{
return yield_under(mod, mod, rb_ary_new4(argc, argv));
}