public Method

Module.const_set(p1, p2)

mod.const_set(sym, obj)     obj

Sets the named constant to the given object, returning that object. Creates a new constant if no constant with the given name previously existed.

Math.const_set("HIGH_SCHOOL_PI", 22.0/7.0)   #=> 3.14285714285714
Math::HIGH_SCHOOL_PI - Math::PI              #=> 0.00126448926734968

Source Code

/*
*  call-seq:
*     mod.const_set(sym, obj)    => obj
*  
*  Sets the named constant to the given object, returning that object.
*  Creates a new constant if no constant with the given name previously
*  existed.
*     
*     Math.const_set("HIGH_SCHOOL_PI", 22.0/7.0)   #=> 3.14285714285714
*     Math::HIGH_SCHOOL_PI - Math::PI              #=> 0.00126448926734968
*/

static VALUE
rb_mod_const_set(mod, name, value)
   VALUE mod, name, value;
{
   ID id = rb_to_id(name);

   if (!rb_is_const_id(id)) {
       rb_name_error(id, "wrong constant name %s", rb_id2name(id));
   }
   rb_const_set(mod, id, value);
   return value;
}
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.