instance method
Module#refine
(::Module mod) { () [self: ::Refinement] -> void } -> ::Refinement
refine(mod) { block } → module
eval.c
View on GitHub ↗
static VALUE
rb_mod_refine(VALUE module, VALUE klass)
{
/* module is the receiver of #refine, klass is a module to be refined (`mod` in the doc) */
rb_thread_t *th = GET_THREAD();
VALUE block_handler = rb_vm_frame_block_handler(th->ec->cfp);
struct rb_refinements_data data;
if (block_handler == VM_BLOCK_HANDLER_NONE) {
rb_raise(rb_eArgError, "no block given");
}
if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
rb_raise(rb_eArgError, "can't pass a Proc as a block to Module#refine");
}
ensure_class_or_module(klass);
rb_refinement_setup(&data, module, klass);
rb_yield_refine_block(data.refinement, data.refinements);
return data.refinement;
}
Refine mod in the receiver.
Returns a module, where refined methods are defined.
Ruby version changes
-
3.1
-
New class which represents a module created by
Module#refine.includeandprependare deprecated, andimport_methodsis added instead. [Bug #17429]
-
See also
#public_method_defined?
#refinements
#public_instance_methods
#remove_class_variable
also in
4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0