public Method

Module.class_variable_get(p1)

mod.class_variable_get(symbol)     obj

Returns the value of the given class variable (or throws a NameError exception). The @@ part of the variable name should be included for regular class variables

class Fred
  @@foo = 99
end

def Fred.foo
  class_variable_get(:@@foo)     #=> 99
end

Source Code

/*
*  call-seq:
*     mod.class_variable_get(symbol)    => obj
*  
*  Returns the value of the given class variable (or throws a
*  <code>NameError</code> exception). The <code>@@</code> part of the
*  variable name should be included for regular class variables
*     
*     class Fred
*       @@foo = 99
*     end
*
*     def Fred.foo
*       class_variable_get(:@@foo)     #=> 99
*     end
*/

static VALUE
rb_mod_cvar_get(obj, iv)
   VALUE obj, iv;
{
   ID id = rb_to_id(iv);

   if (!rb_is_class_id(id)) {
       rb_name_error(id, "`%s' is not allowed as a class variable name", rb_id2name(id));
   }
   return rb_cvar_get(obj, id);
}
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.