public Method

Module.ancestors

mod.ancestors  array

Returns a list of modules included in mod (including mod itself).

module Mod
  include Math
  include Comparable
end

Mod.ancestors    #=> [Mod, Comparable, Math]
Math.ancestors   #=> [Math]

Source Code

/*
*  call-seq:
*     mod.ancestors -> array
*  
*  Returns a list of modules included in <i>mod</i> (including
*  <i>mod</i> itself).
*     
*     module Mod
*       include Math
*       include Comparable
*     end
*     
*     Mod.ancestors    #=> [Mod, Comparable, Math]
*     Math.ancestors   #=> [Math]
*/

VALUE
rb_mod_ancestors(mod)
   VALUE mod;
{
   VALUE p, ary = rb_ary_new();

   for (p = mod; p; p = RCLASS(p)->super) {
if (FL_TEST(p, FL_SINGLETON))
    continue;
if (BUILTIN_TYPE(p) == T_ICLASS) {
    rb_ary_push(ary, RBASIC(p)->klass);
}
else {
    rb_ary_push(ary, p);
}
   }
   return ary;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.