End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Module.used_modules
used_modules → array
eval.c
View on GitHub ↗
static VALUE
rb_mod_s_used_modules(VALUE _)
{
const rb_cref_t *cref = rb_vm_cref();
VALUE ary = rb_ary_new();
while (cref) {
if (!NIL_P(CREF_REFINEMENTS(cref))) {
rb_hash_foreach(CREF_REFINEMENTS(cref), used_modules_i, ary);
}
cref = CREF_NEXT(cref);
}
return rb_funcall(ary, rb_intern("uniq"), 0);
}
Returns an array of all modules used in the current scope. The ordering of modules in the resulting array is not defined.
Example
module A refine Object do end end module B refine Object do end end using A using B p Module.used_modules
produces:
Example
[B, A]