Ruby
3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
|
Data Structures | |
struct | clone_method_arg |
struct | clone_const_arg |
struct | cvc_table_copy_ctx |
struct | subclass_traverse_data |
struct | method_entry_arg |
Macros | |
#define | METACLASS_OF(k) RBASIC(k)->klass |
#define | SET_METACLASS_OF(k, cls) RBASIC_SET_CLASS(k, cls) |
#define | META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k)) |
whether k is a meta^(n)-class of Class class More... | |
#define | HAVE_METACLASS_P(k) |
whether k has a metaclass More... | |
#define | ENSURE_EIGENCLASS(klass) (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass)) |
ensures klass belongs to its own eigenclass. More... | |
Enumerations | |
enum | { RMODULE_ALLOCATED_BUT_NOT_INITIALIZED = RUBY_FL_USER1 } |
If this flag is set, that module is allocated but not initialized yet. More... | |
Functions | |
static rb_subclass_entry_t * | push_subclass_entry_to_list (VALUE super, VALUE klass) |
void | rb_class_subclass_add (VALUE super, VALUE klass) |
static void | rb_module_add_to_subclasses_list (VALUE module, VALUE iclass) |
void | rb_class_remove_subclass_head (VALUE klass) |
void | rb_class_remove_from_super_subclasses (VALUE klass) |
void | rb_class_remove_from_module_subclasses (VALUE klass) |
void | rb_class_foreach_subclass (VALUE klass, void(*f)(VALUE, VALUE), VALUE arg) |
static void | class_detach_subclasses (VALUE klass, VALUE arg) |
void | rb_class_detach_subclasses (VALUE klass) |
static void | class_detach_module_subclasses (VALUE klass, VALUE arg) |
void | rb_class_detach_module_subclasses (VALUE klass) |
static VALUE | class_alloc (VALUE flags, VALUE klass) |
Allocates a struct RClass for a new class. More... | |
static void | RCLASS_M_TBL_INIT (VALUE c) |
VALUE | rb_class_boot (VALUE super) |
A utility function that wraps class_alloc. More... | |
static VALUE * | class_superclasses_including_self (VALUE klass) |
void | rb_class_update_superclasses (VALUE klass) |
void | rb_check_inheritable (VALUE super) |
Asserts that the given class can derive a child class. More... | |
VALUE | rb_class_new (VALUE super) |
Creates a new, anonymous class. More... | |
VALUE | rb_class_s_alloc (VALUE klass) |
static void | clone_method (VALUE old_klass, VALUE new_klass, ID mid, const rb_method_entry_t *me) |
static enum rb_id_table_iterator_result | clone_method_i (ID key, VALUE value, void *data) |
static int | clone_const (ID key, const rb_const_entry_t *ce, struct clone_const_arg *arg) |
static enum rb_id_table_iterator_result | clone_const_i (ID key, VALUE value, void *data) |
static void | class_init_copy_check (VALUE clone, VALUE orig) |
static enum rb_id_table_iterator_result | cvc_table_copy (ID id, VALUE val, void *data) |
static void | copy_tables (VALUE clone, VALUE orig) |
static bool | ensure_origin (VALUE klass) |
static bool | RMODULE_UNINITIALIZED (VALUE module) |
void | rb_module_set_initialized (VALUE mod) |
void | rb_module_check_initializable (VALUE mod) |
VALUE | rb_mod_init_copy (VALUE clone, VALUE orig) |
The comment that comes with this function says :nodoc: . More... | |
VALUE | rb_singleton_class_clone (VALUE obj) |
Clones a singleton class. More... | |
VALUE | rb_singleton_class_clone_and_attach (VALUE obj, VALUE attach) |
void | rb_singleton_class_attached (VALUE klass, VALUE obj) |
Attaches a singleton class to its corresponding object. More... | |
static int | rb_singleton_class_has_metaclass_p (VALUE sklass) |
int | rb_singleton_class_internal_p (VALUE sklass) |
static VALUE | make_metaclass (VALUE klass) |
Creates a metaclass of klass More... | |
static VALUE | make_singleton_class (VALUE obj) |
Creates a singleton class for obj . More... | |
static VALUE | boot_defclass (const char *name, VALUE super) |
VALUE | rb_make_metaclass (VALUE obj, VALUE unused) |
VALUE | rb_define_class_id (ID id, VALUE super) |
This is a very badly designed API that creates an anonymous class. More... | |
VALUE | rb_class_inherited (VALUE super, VALUE klass) |
Calls Class::inherited. More... | |
VALUE | rb_define_class (const char *name, VALUE super) |
Defines a top-level class. More... | |
VALUE | rb_define_class_under (VALUE outer, const char *name, VALUE super) |
Defines a class under the namespace of outer . More... | |
VALUE | rb_define_class_id_under_no_pin (VALUE outer, ID id, VALUE super) |
VALUE | rb_define_class_id_under (VALUE outer, ID id, VALUE super) |
Identical to rb_define_class_under(), except it takes the name in ID instead of C's string. More... | |
VALUE | rb_module_s_alloc (VALUE klass) |
static VALUE | module_new (VALUE klass) |
VALUE | rb_module_new (void) |
Creates a new, anonymous module. More... | |
VALUE | rb_refinement_new (void) |
Creates a new, anonymous refinement. More... | |
VALUE | rb_define_module_id (ID id) |
This is a very badly designed API that creates an anonymous module. More... | |
VALUE | rb_define_module (const char *name) |
Defines a top-level module. More... | |
VALUE | rb_define_module_under (VALUE outer, const char *name) |
Defines a module under the namespace of outer . More... | |
VALUE | rb_define_module_id_under (VALUE outer, ID id) |
Identical to rb_define_module_under(), except it takes the name in ID instead of C's string. More... | |
VALUE | rb_include_class_new (VALUE module, VALUE super) |
static int | include_modules_at (const VALUE klass, VALUE c, VALUE module, int search_super) |
static void | ensure_includable (VALUE klass, VALUE module) |
void | rb_include_module (VALUE klass, VALUE module) |
Includes a module to a class. More... | |
static enum rb_id_table_iterator_result | add_refined_method_entry_i (ID key, VALUE value, void *data) |
static enum rb_id_table_iterator_result | clear_module_cache_i (ID id, VALUE val, void *data) |
static bool | module_in_super_chain (const VALUE klass, VALUE module) |
static enum rb_id_table_iterator_result | clear_constant_cache_i (ID id, VALUE value, void *data) |
static int | do_include_modules_at (const VALUE klass, VALUE c, VALUE module, int search_super, bool check_cyclic) |
static enum rb_id_table_iterator_result | move_refined_method (ID key, VALUE value, void *data) |
static enum rb_id_table_iterator_result | cache_clear_refined_method (ID key, VALUE value, void *data) |
void | rb_prepend_module (VALUE klass, VALUE module) |
Identical to rb_include_module(), except it "prepends" the passed module to the klass, instead of includes. More... | |
VALUE | rb_mod_included_modules (VALUE mod) |
Queries the list of included modules. More... | |
VALUE | rb_mod_include_p (VALUE mod, VALUE mod2) |
Queries if the passed module is included by the module. More... | |
VALUE | rb_mod_ancestors (VALUE mod) |
Queries the module's ancestors. More... | |
static void | class_descendants_recursive (VALUE klass, VALUE v) |
static VALUE | class_descendants (VALUE klass, bool immediate_only) |
VALUE | rb_class_subclasses (VALUE klass) |
Queries the class's direct descendants. More... | |
VALUE | rb_class_attached_object (VALUE klass) |
Returns the attached object for a singleton class. More... | |
static void | ins_methods_push (st_data_t name, st_data_t ary) |
static int | ins_methods_i (st_data_t name, st_data_t type, st_data_t ary) |
static int | ins_methods_type_i (st_data_t name, st_data_t type, st_data_t ary, rb_method_visibility_t visi) |
static int | ins_methods_prot_i (st_data_t name, st_data_t type, st_data_t ary) |
static int | ins_methods_priv_i (st_data_t name, st_data_t type, st_data_t ary) |
static int | ins_methods_pub_i (st_data_t name, st_data_t type, st_data_t ary) |
static int | ins_methods_undef_i (st_data_t name, st_data_t type, st_data_t ary) |
static enum rb_id_table_iterator_result | method_entry_i (ID key, VALUE value, void *data) |
static void | add_instance_method_list (VALUE mod, struct method_entry_arg *me_arg) |
static bool | particular_class_p (VALUE mod) |
static VALUE | class_instance_method_list (int argc, const VALUE *argv, VALUE mod, int obj, int(*func)(st_data_t, st_data_t, st_data_t)) |
VALUE | rb_class_instance_methods (int argc, const VALUE *argv, VALUE mod) |
Generates an array of symbols, which are the list of method names defined in the passed class. More... | |
VALUE | rb_class_protected_instance_methods (int argc, const VALUE *argv, VALUE mod) |
Identical to rb_class_instance_methods(), except it returns names of methods that are protected only. More... | |
VALUE | rb_class_private_instance_methods (int argc, const VALUE *argv, VALUE mod) |
Identical to rb_class_instance_methods(), except it returns names of methods that are private only. More... | |
VALUE | rb_class_public_instance_methods (int argc, const VALUE *argv, VALUE mod) |
Identical to rb_class_instance_methods(), except it returns names of methods that are public only. More... | |
VALUE | rb_class_undefined_instance_methods (VALUE mod) |
VALUE | rb_obj_methods (int argc, const VALUE *argv, VALUE obj) |
VALUE | rb_obj_protected_methods (int argc, const VALUE *argv, VALUE obj) |
VALUE | rb_obj_private_methods (int argc, const VALUE *argv, VALUE obj) |
VALUE | rb_obj_public_methods (int argc, const VALUE *argv, VALUE obj) |
VALUE | rb_obj_singleton_methods (int argc, const VALUE *argv, VALUE obj) |
Identical to rb_class_instance_methods(), except it returns names of singleton methods instead of instance methods. More... | |
static VALUE | special_singleton_class_of (VALUE obj) |
VALUE | rb_special_singleton_class (VALUE obj) |
static VALUE | singleton_class_of (VALUE obj) |
void | rb_freeze_singleton_class (VALUE x) |
This is an implementation detail of RB_OBJ_FREEZE(). More... | |
VALUE | rb_singleton_class_get (VALUE obj) |
Returns the singleton class of obj , or nil if obj is not a singleton object. More... | |
VALUE | rb_singleton_class (VALUE obj) |
Finds or creates the singleton class of the passed object. More... | |
void | rb_class_modify_check (VALUE klass) |
Asserts that klass is not a frozen class. More... | |
void | rb_extend_object (VALUE obj, VALUE mod) |
Extend the object with the module. More... | |
Variables | |
rb_serial_t | ruby_vm_global_cvar_state |
#define ENSURE_EIGENCLASS | ( | klass | ) | (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass)) |
#define HAVE_METACLASS_P | ( | k | ) |
whether k has a metaclass
1 | if k has a metaclass |
0 | otherwise |
#define META_CLASS_OF_CLASS_CLASS_P | ( | k | ) | (METACLASS_OF(k) == (k)) |
anonymous enum |
Allocates a struct RClass for a new class.
flags | initial value for basic.flags of the returned class. |
klass | the class of the returned class. |
klass
must refer Class
class or an ancestor of Class. (flags | T_CLASS) != 0
#initialize
'd.Definition at line 239 of file class.c.
Referenced by rb_class_boot().
Creates a metaclass of klass
klass | a class |
klass
is a Class object klass
has no singleton class. klass
is the returned class. klass
is a meta^(n)-klass for n >= 0 void rb_check_inheritable | ( | VALUE | super | ) |
Asserts that the given class can derive a child class.
A class might or might not be able to do so; for instance a singleton class cannot.
[in] | super | Possible super class. |
rb_eTypeError | No it cannot. |
super
can derive. Definition at line 344 of file class.c.
Referenced by rb_class_new().
A utility function that wraps class_alloc.
allocates a class and initializes safely.
super | a class from which the new class derives. |
super
must be a class. Definition at line 281 of file class.c.
Referenced by make_metaclass(), and rb_class_new().
Generates an array of symbols, which are the list of method names defined in the passed class.
[in] | argc | Number of objects of argv . |
[in] | argv | Array of at most one object, which controls (if any) whether the return array includes the names of methods defined in ancestors or not. |
[in] | mod | A module or a class. |
rb_eArgError | argc out of range. |
mod
. void rb_class_modify_check | ( | VALUE | klass | ) |
Asserts that klass
is not a frozen class.
[in] | klass | a Module object |
RuntimeError | if klass is not a class or frozen. |
Definition at line 419 of file eval.c.
Referenced by rb_alias(), rb_deprecate_constant(), and rb_undef().
Identical to rb_class_instance_methods(), except it returns names of methods that are private only.
[in] | argc | Number of objects of argv . |
[in] | argv | Array of at most one object, which controls (if any) whether the return array includes the names of methods defined in ancestors or not. |
[in] | mod | A module or a class. |
rb_eArgError | argc out of range. |
mod
. Identical to rb_class_instance_methods(), except it returns names of methods that are protected only.
[in] | argc | Number of objects of argv . |
[in] | argv | Array of at most one object, which controls (if any) whether the return array includes the names of methods defined in ancestors or not. |
[in] | mod | A module or a class. |
rb_eArgError | argc out of range. |
mod
. Identical to rb_class_instance_methods(), except it returns names of methods that are public only.
[in] | argc | Number of objects of argv . |
[in] | argv | Array of at most one object, which controls (if any) whether the return array includes the names of methods defined in ancestors or not. |
[in] | mod | A module or a class. |
rb_eArgError | argc out of range. |
mod
. Queries the class's direct descendants.
This routine gathers classes that are direct subclasses of the given class, returning an array of classes that have the given class as a superclass. The returned array does not include singleton classes.
[in] | klass | A class. |
klass
is the superclass
. Defines a top-level class.
[in] | name | Name of the class. |
[in] | super | A class from which the new class will derive. |
rb_eTypeError | The constant name name is already taken but the constant is not a class. |
rb_eTypeError | The class is already defined but the class can not be reopened because its superclass is not super . |
rb_eArgError | super is NULL. |
name
refers the returned class. name
is already defined and its superclass is super
, the function just returns the defined class. This is a very badly designed API that creates an anonymous class.
[in] | id | Discarded for no reason (why...). |
[in] | super | What would become a parent class. 0 means rb_cObject. |
rb_eTypeError | super is not something inheritable. |
super
. Identical to rb_define_class_under(), except it takes the name in ID instead of C's string.
[out] | outer | A class which contains the new class. |
[in] | id | Name of the new class |
[in] | super | A class from which the new class will derive. 0 means rb_cObject. |
rb_eTypeError | The constant name id is already taken but the constant is not a class. |
rb_eTypeError | The class is already defined but the class can not be reopened because its superclass is not super . |
rb_eArgError | super is NULL. |
outer::id
refers the returned class. id
is already defined and its superclass is super
, the function just returns the defined class. Definition at line 1051 of file class.c.
Referenced by rb_define_class_under(), and rb_struct_define_under().
Defines a class under the namespace of outer
.
[out] | outer | A class which contains the new class. |
[in] | name | Name of the new class |
[in] | super | A class from which the new class will derive. 0 means rb_cObject. |
rb_eTypeError | The constant name name is already taken but the constant is not a class. |
rb_eTypeError | The class is already defined but the class can not be reopened because its superclass is not super . |
rb_eArgError | super is NULL. |
outer::name
refers the returned class. name
is already defined and its superclass is super
, the function just returns the defined class. VALUE rb_define_module | ( | const char * | name | ) |
Defines a top-level module.
[in] | name | Name of the module. |
rb_eTypeError | The constant name name is already taken but the constant is not a module. |
name
refers the returned module. Identical to rb_define_module_under(), except it takes the name in ID instead of C's string.
[out] | outer | A class which contains the new module. |
[in] | id | Name of the new module |
rb_eTypeError | The constant name id is already taken but the constant is not a module. |
outer::id
refers the returned module. Definition at line 1125 of file class.c.
Referenced by rb_define_module_under().
Defines a module under the namespace of outer
.
[out] | outer | A class which contains the new module. |
[in] | name | Name of the new module |
rb_eTypeError | The constant name name is already taken but the constant is not a class. |
outer::name
refers the returned module. Extend the object with the module.
Module#extend_object
, not Object#extend
! These two methods are very similar, but not identical. The difference is the hook. Module#extend_object
does not invoke Module#extended
, while Object#extend
does. [out] | obj | Object to extend. |
[in] | mod | Module of extension. |
Definition at line 1735 of file eval.c.
Referenced by rb_eval_string_wrap().
void rb_freeze_singleton_class | ( | VALUE | klass | ) |
This is an implementation detail of RB_OBJ_FREEZE().
People don't use it directly.
[out] | klass | A singleton class. |
klass
gets frozen. Definition at line 2263 of file class.c.
Referenced by rb_obj_freeze_inline().
Includes a module to a class.
[out] | klass | Inclusion destination. |
[in] | module | Inclusion source. |
rb_eArgError | Cyclic inclusion. |
Definition at line 1187 of file class.c.
Referenced by rb_extend_object().
Queries the module's ancestors.
This routine gathers classes and modules that the passed module either inherits, includes, or prepends, then recursively applies that routine again and again to the collected entries until the list doesn't grow up.
[in] | mod | A module or a class. |
mod
possibly recursively inherits, includes, or prepends. Queries if the passed module is included by the module.
It can also be seen as a routine to first call rb_mod_included_modules(), then see if the return value contains the passed module.
[in] | child | A Module. |
[in] | parent | Another Module. |
rb_eTypeError | child is not an instance of rb_cModule. |
RUBY_Qtrue | parent is either included or prepended in any of child 's ancestry tree (including itself). |
Queries the list of included modules.
It can also be seen as a routine to first call rb_mod_ancestors(), then rejects non-modules from the return value.
[in] | mod | Class or Module. |
mod
's ancestry tree (including itself). VALUE rb_module_new | ( | void | ) |
Creates a new, anonymous module.
Definition at line 1076 of file class.c.
Referenced by rb_define_module_id(), rb_define_module_id_under(), and rb_eval_string_wrap().
Identical to rb_class_instance_methods(), except it returns names of singleton methods instead of instance methods.
[in] | argc | Number of objects of argv . |
[in] | argv | Array of at most one object, which controls (if any) whether the return array includes the names of methods defined in ancestors or not. |
[in] | obj | Arbitrary ruby object. |
rb_eArgError | argc out of range. |
obj
. Identical to rb_include_module(), except it "prepends" the passed module to the klass, instead of includes.
This affects how super
resolves. For instance:
[out] | klass | Target class to modify. |
[in] | module | Module to prepend. |
rb_eArgError | Cyclic inclusion. |
VALUE rb_refinement_new | ( | void | ) |
Finds or creates the singleton class of the passed object.
[out] | obj | Arbitrary ruby object. |
rb_eTypeError | obj cannot have its singleton class. |
obj
has its singleton class, which is the return value. obj
is a class, the returned singleton class also has its own singleton class in order to keep consistency of the inheritance structure of metaclasses. obj
did not have one. Definition at line 2297 of file class.c.
Referenced by rb_extend_object(), and rb_obj_singleton_methods().
Attaches a singleton class to its corresponding object.
This is basically an implementation detail of rb_clone_setup(). People need not be aware of this working behind-the-scene.
[in] | klass | The singleton class. |
[out] | obj | The object to attach a class. |
klass
becomes a singleton class of obj
. klass
becomes the singleton class of obj
. Definition at line 709 of file class.c.
Referenced by make_metaclass().
Clones a singleton class.
An object can have its own singleton class. OK. Then what happens when a program clones such object? The singleton class that is attached to the source object must also be cloned. Otherwise a singleton object gets shared with two objects, which breaks "singleton"-ness of such class.
This is basically an implementation detail of rb_clone_setup(). People need not be aware of this working behind-the-scene.
[in] | obj | The object that has its own singleton class. |