instance method
Module#prepend
(::Module, *::Module arg0) -> self
prepend(module, ...) → self
eval.c
View on GitHub ↗
static VALUE
rb_mod_prepend(int argc, VALUE *argv, VALUE module)
{
int i;
ID id_prepend_features, id_prepended;
if (BUILTIN_TYPE(module) == T_MODULE && FL_TEST(module, RMODULE_IS_REFINEMENT)) {
rb_raise(rb_eTypeError, "Refinement#prepend has been removed");
}
CONST_ID(id_prepend_features, "prepend_features");
CONST_ID(id_prepended, "prepended");
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
for (i = 0; i < argc; i++) {
Check_Type(argv[i], T_MODULE);
if (FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
rb_raise(rb_eTypeError, "Cannot prepend refinement");
}
}
while (argc--) {
rb_funcall(argv[argc], id_prepend_features, 1, module);
rb_funcall(argv[argc], id_prepended, 1, module);
}
return module;
}
Invokes Module.prepend_features on each parameter in reverse order.
Ruby version changes
-
3.1
-
Module#prependnow modifies the ancestor chain if the receiver already includes the argument.Module#prependstill does not modify the ancestor chain if the receiver has already prepended the argument. [Bug #17423]
-
-
3.0
-
Module#includeandModule#prependnow affect classes and modules that have already included or prepended the receiver, mirroring the behavior if the arguments were included in the receiver before the other modules and classes included or prepended the receiver. [Feature #9573]Exampleclass C; end module M1; end module M2; end C.include M1 M1.include M2 p C.ancestors #=> [C, M1, M2, Object, Kernel, BasicObject]
-
See also
#name
#prepended
#module_function
#prepend_features
also in
4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0