Method: Module.nesting

Defined in:
eval.c

.nestingArray

Returns the list of Modules nested at the point of call.

module M1
  module M2
    $a = Module.nesting
  end
end
$a           #=> [M1::M2, M1]
$a[0].name   #=> "M1::M2"


361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'eval.c', line 361

static VALUE
rb_mod_nesting(VALUE _)
{
    VALUE ary = rb_ary_new();
    const rb_cref_t *cref = rb_vm_cref();

    while (cref && CREF_NEXT(cref)) {
  VALUE klass = CREF_CLASS(cref);
  if (!CREF_PUSHED_BY_EVAL(cref) &&
      !NIL_P(klass)) {
      rb_ary_push(ary, klass);
  }
  cref = CREF_NEXT(cref);
    }
    return ary;
}