method
remove_const
v1_8_7_72 -
Show latest stable
- Class:
Module
remove_const(p1)public
Removes the definition of the given constant, returning that constant’s value. Predefined classes and singleton objects (such as true) cannot be removed.
/*
* call-seq:
* remove_const(sym) => obj
*
* Removes the definition of the given constant, returning that
* constant's value. Predefined classes and singleton objects (such as
* <i>true</i>) cannot be removed.
*/
VALUE
rb_mod_remove_const(mod, name)
VALUE mod, name;
{
ID id = rb_to_id(name);
VALUE val;
if (!rb_is_const_id(id)) {
rb_name_error(id, "`%s' is not allowed as a constant name", rb_id2name(id));
}
if (!OBJ_TAINTED(mod) && rb_safe_level() >= 4)
rb_raise(rb_eSecurityError, "Insecure: can't remove constant");
if (OBJ_FROZEN(mod)) rb_error_frozen("class/module");
if (RCLASS(mod)->iv_tbl && st_delete(ROBJECT(mod)->iv_tbl, (st_data_t*)&id, &val)) {
if (val == Qundef) {
autoload_delete(mod, id);
val = Qnil;
}
return val;
}
if (rb_const_defined_at(mod, id)) {
rb_name_error(id, "cannot remove %s::%s",
rb_class2name(mod), rb_id2name(id));
}
rb_name_error(id, "constant %s::%s not defined",
rb_class2name(mod), rb_id2name(id));
return Qnil; /* not reached */
} Related methods
- Instance methods
- <
- <=
- <=>
- ==
- ===
- >
- >=
- alias_method
- ancestors
- append_features
- attr
- attr_accessor
- attr_reader
- attr_writer
- autoload
- autoload?
- class_eval
- class_exec
- class_variable_defined?
- class_variable_get
- class_variable_set
- class_variables
- const_defined?
- const_get
- const_missing
- const_set
- constants
- define_method
- extend_object
- extended
- freeze
- include
- include?
- included
- included_modules
- initialize_copy
- instance_method
- instance_methods
- method_added
- method_defined?
- method_removed
- method_undefined
- module_eval
- module_exec
- module_function
- name
- private
- private_class_method
- private_instance_methods
- private_method_defined?
- protected
- protected_instance_methods
- protected_method_defined?
- public
- public_class_method
- public_instance_methods
- public_method_defined?
- remove_class_variable
- remove_const
- remove_method
- to_s
- undef_method
- Class methods
- constants
- nesting
- new