method
remove_const
v1_9_1_378 -
Show latest stable
- Class:
Module
remove_const(p1)private
Removes the definition of the given constant, returning that constant’s value. Predefined classes and singleton objects (such as true) cannot be removed.
VALUE
rb_mod_remove_const(VALUE mod, VALUE name)
{
const ID id = rb_to_id(name);
VALUE val;
st_data_t v, n = id;
rb_vm_change_state();
if (!rb_is_const_id(id)) {
rb_name_error(id, "`%s' is not allowed as a constant name", rb_id2name(id));
}
if (!OBJ_UNTRUSTED(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_IV_TBL(mod) && st_delete(RCLASS_IV_TBL(mod), &n, &v)) {
val = (VALUE)v;
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
- <
- <=
- <=>
- ==
- ===
- >
- >=
- ancestors
- 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
- freeze
- include?
- included_modules
- initialize_copy
- instance_method
- instance_methods
- method_defined?
- module_eval
- module_exec
- name
- private_class_method
- private_instance_methods
- private_method_defined?
- protected_instance_methods
- protected_method_defined?
- public_class_method
- public_instance_method
- public_instance_methods
- public_method_defined?
- remove_class_variable
- to_s
- Class methods
- constants
- nesting
- new
- Private methods
-
alias_method -
append_features -
attr -
attr_accessor -
attr_reader -
attr_writer -
define_method -
extend_object -
extended -
include -
included -
method_added -
method_removed -
method_undefined -
module_function -
private -
protected -
public -
remove_const -
remove_method -
undef_method