static public Method

Module.constants

Module.constants    array

Returns an array of the names of all constants defined in the system. This list includes the names of all modules and classes.

p Module.constants.sort[1..5]

produces:

["ARGV", "ArgumentError", "Array", "Bignum", "Binding"]

Source Code

/*
*  call-seq:
*     Module.constants   => array
*  
*  Returns an array of the names of all constants defined in the
*  system. This list includes the names of all modules and classes.
*     
*     p Module.constants.sort[1..5]
*     
*  <em>produces:</em>
*     
*     ["ARGV", "ArgumentError", "Array", "Bignum", "Binding"]
*/

static VALUE
rb_mod_s_constants()
{
   NODE *cbase = ruby_cref;
   void *data = 0;

   while (cbase) {
       if (!NIL_P(cbase->nd_clss)) {
           data = rb_mod_const_at(cbase->nd_clss, data);
       }
       cbase = cbase->nd_next;
   }

   if (!NIL_P(ruby_cbase)) {
       data = rb_mod_const_of(ruby_cbase, data);
   }
   return rb_const_list(data);
}
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.