Method: Module#class_variable_set

Defined in:
object.c

#class_variable_set(symbol, obj) ⇒ Object #class_variable_set(string, obj) ⇒ Object

Sets the class variable named by symbol to the given object. If the class variable name is passed as a string, that string is converted to a symbol.

class Fred
  @@foo = 99
  def foo
    @@foo
  end
end
Fred.class_variable_set(:@@foo, 101)     #=> 101
Fred.new.foo                             #=> 101

Overloads:

  • #class_variable_set(symbol, obj) ⇒ Object

    Returns:

  • #class_variable_set(string, obj) ⇒ Object

    Returns:



3039
3040
3041
3042
3043
3044
3045
3046
# File 'object.c', line 3039

static VALUE
rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val)
{
    ID id = id_for_var(obj, iv, class);
    if (!id) id = rb_intern_str(iv);
    rb_cvar_set(obj, id, val);
    return val;
}