public Method

Module.class_variables

mod.class_variables    array

Returns an array of the names of class variables in mod and the ancestors of mod.

class One
  @@var1 = 1
end
class Two < One
  @@var2 = 2
end
One.class_variables   #=> ["@@var1"]
Two.class_variables   #=> ["@@var2", "@@var1"]

Source Code

/*
*  call-seq:
*     mod.class_variables   => array
*  
*  Returns an array of the names of class variables in <i>mod</i> and
*  the ancestors of <i>mod</i>.
*     
*     class One
*       @@var1 = 1
*     end
*     class Two < One
*       @@var2 = 2
*     end
*     One.class_variables   #=> ["@@var1"]
*     Two.class_variables   #=> ["@@var2", "@@var1"]
*/

VALUE
rb_mod_class_variables(obj)
   VALUE obj;
{
   VALUE ary = rb_ary_new();

   for (;;) {
if (RCLASS(obj)->iv_tbl) {
    st_foreach_safe(RCLASS(obj)->iv_tbl, cv_i, ary);
}
obj = RCLASS(obj)->super;
if (!obj) break;
   }
   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.