Feature #3908 » 0003-add-Module-public_constant-and-private_constant.patch
object.c | ||
---|---|---|
rb_define_method(rb_cModule, "class_variable_get", rb_mod_cvar_get, 1);
|
||
rb_define_method(rb_cModule, "class_variable_set", rb_mod_cvar_set, 2);
|
||
rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
|
||
rb_define_method(rb_cModule, "public_constant", rb_mod_public_constant, -1);
|
||
rb_define_method(rb_cModule, "private_constant", rb_mod_private_constant, -1);
|
||
rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
|
||
rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
|
variable.c | ||
---|---|---|
while (RTEST(tmp)) {
|
||
VALUE am = 0;
|
||
while (RCLASS_CONST_TBL(tmp) && st_lookup(RCLASS_CONST_TBL(tmp), (st_data_t)id, &v)) {
|
||
value = ((rb_const_entry_t*)v)->value;
|
||
rb_const_entry_t *ce = (rb_const_entry_t *)v;
|
||
value = ce->value;
|
||
if (value == Qundef) {
|
||
if (am == tmp) break;
|
||
am = tmp;
|
||
... | ... | |
rb_warn("toplevel constant %s referenced by %s::%s",
|
||
rb_id2name(id), rb_class2name(klass), rb_id2name(id));
|
||
}
|
||
if (ce->flag == CONST_PRIVATE) {
|
||
rb_name_error(id, "private constant %s::%s referenced", rb_class2name(klass), rb_id2name(id));
|
||
}
|
||
return value;
|
||
}
|
||
if (!recurse && klass != rb_cObject) break;
|
||
... | ... | |
rb_define_const(rb_cObject, name, val);
|
||
}
|
||
static void
|
||
set_const_visibility(VALUE mod, int argc, VALUE *argv, rb_const_flag_t flag)
|
||
{
|
||
int i;
|
||
st_data_t v;
|
||
ID id;
|
||
if (rb_safe_level() >= 4 && !OBJ_UNTRUSTED(mod)) {
|
||
rb_raise(rb_eSecurityError,
|
||
"Insecure: can't change method visibility");
|
||
}
|
||
for (i = 0; i < argc; i++) {
|
||
id = rb_to_id(argv[i]);
|
||
if (RCLASS_CONST_TBL(mod) && st_lookup(RCLASS_CONST_TBL(mod), (st_data_t)id, &v)) {
|
||
((rb_const_entry_t*)v)->flag = flag;
|
||
return;
|
||
}
|
||
rb_name_error(id, "constant %s::%s not defined", rb_class2name(mod), rb_id2name(id));
|
||
}
|
||
rb_clear_cache_by_class(mod);
|
||
}
|
||
/*
|
||
* call-seq:
|
||
* mod.private_constant(symbol, ...) => mod
|
||
*
|
||
* Makes a list of existing constants private.
|
||
*/
|
||
VALUE
|
||
rb_mod_private_constant(int argc, VALUE *argv, VALUE obj)
|
||
{
|
||
set_const_visibility(obj, argc, argv, CONST_PRIVATE);
|
||
return obj;
|
||
}
|
||
/*
|
||
* call-seq:
|
||
* mod.public_constant(symbol, ...) => mod
|
||
*
|
||
* Makes a list of existing constants public.
|
||
*/
|
||
VALUE
|
||
rb_mod_public_constant(int argc, VALUE *argv, VALUE obj)
|
||
{
|
||
set_const_visibility(obj, argc, argv, CONST_PUBLIC);
|
||
return obj;
|
||
}
|
||
static VALUE
|
||
original_module(VALUE c)
|
||
{
|
- « Previous
- 1
- 2
- 3
- Next »