Ruby  2.4.2p198(2017-09-14revision59899)
Data Structures | Macros | Functions
Classes and their hierarchy.

Data Structures

struct  clone_method_arg
 
struct  clone_const_arg
 
struct  method_entry_arg
 

Macros

#define id_attached   id__attached__
 
#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...
 
#define SPECIAL_SINGLETON(x, c)
 

Functions

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_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...
 
void rb_check_inheritable (VALUE super)
 Ensures a class can be derived from super. More...
 
VALUE rb_class_new (VALUE super)
 Creates a new class. More...
 
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)
 
VALUE rb_mod_init_copy (VALUE clone, VALUE orig)
 
VALUE rb_singleton_class_clone (VALUE obj)
 
VALUE rb_singleton_class_clone_and_attach (VALUE obj, VALUE attach)
 
void rb_singleton_class_attached (VALUE klass, VALUE obj)
 Attach a object to a singleton class. 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)
 
void Init_class_hierarchy (void)
 
VALUE rb_make_metaclass (VALUE obj, VALUE unused)
 
VALUE rb_define_class_id (ID id, VALUE super)
 Defines a new 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 (VALUE outer, ID id, VALUE super)
 Defines a class under the namespace of outer. More...
 
VALUE rb_module_new (void)
 
VALUE rb_define_module_id (ID id)
 
VALUE rb_define_module (const char *name)
 
VALUE rb_define_module_under (VALUE outer, const char *name)
 
VALUE rb_define_module_id_under (VALUE outer, ID id)
 
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)
 
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 move_refined_method (ID key, VALUE value, void *data)
 
void rb_prepend_module (VALUE klass, VALUE module)
 
VALUE rb_mod_included_modules (VALUE mod)
 
VALUE rb_mod_include_p (VALUE mod, VALUE mod2)
 
VALUE rb_mod_ancestors (VALUE mod)
 
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_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 enum rb_id_table_iterator_result method_entry_i (ID key, VALUE value, void *data)
 
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)
 
VALUE rb_class_protected_instance_methods (int argc, const VALUE *argv, VALUE mod)
 
VALUE rb_class_private_instance_methods (int argc, const VALUE *argv, VALUE mod)
 
VALUE rb_class_public_instance_methods (int argc, const VALUE *argv, 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)
 
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)
 
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)
 Returns the singleton class of obj. More...
 
void InitVM_Object (void)
 Initializes the world of objects and classes. More...
 

Detailed Description

Terminology
  • class: same as in Ruby.
  • singleton class: class for a particular object
  • eigenclass: = singleton class
  • metaclass: class of a class. metaclass is a kind of singleton class.
  • metametaclass: class of a metaclass.
  • meta^(n)-class: class of a meta^(n-1)-class.
  • attached object: A singleton class knows its unique instance. The instance is called the attached object for the singleton class.

Macro Definition Documentation

◆ ENSURE_EIGENCLASS

#define ENSURE_EIGENCLASS (   klass)    (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass))

ensures klass belongs to its own eigenclass.

Returns
the eigenclass of klass
Postcondition
klass belongs to the returned eigenclass. i.e. the attached object of the eigenclass is klass.
Note
this macro creates a new eigenclass if necessary.

Definition at line 472 of file class.c.

Referenced by make_metaclass(), and rb_singleton_class().

◆ HAVE_METACLASS_P

#define HAVE_METACLASS_P (   k)
Value:
rb_singleton_class_has_metaclass_p(k))
#define FL_SINGLETON
Definition: ruby.h:1215
#define FL_TEST(x, f)
Definition: ruby.h:1284
#define METACLASS_OF(k)
Definition: class.c:433

whether k has a metaclass

Return values
1if k has a metaclass
0otherwise

Definition at line 461 of file class.c.

◆ id_attached

#define id_attached   id__attached__

◆ META_CLASS_OF_CLASS_CLASS_P

#define META_CLASS_OF_CLASS_CLASS_P (   k)    (METACLASS_OF(k) == (k))

whether k is a meta^(n)-class of Class class

Return values
1if k is a meta^(n)-class of Class class (n >= 0)
0otherwise

Definition at line 441 of file class.c.

Referenced by make_metaclass().

◆ METACLASS_OF

#define METACLASS_OF (   k)    RBASIC(k)->klass

◆ SET_METACLASS_OF

#define SET_METACLASS_OF (   k,
  cls 
)    RBASIC_SET_CLASS(k, cls)

Definition at line 434 of file class.c.

Referenced by make_metaclass(), and make_singleton_class().

◆ SPECIAL_SINGLETON

#define SPECIAL_SINGLETON (   x,
 
)
Value:
do {\
if (obj == (x)) {\
return (c);\
}\
} while (0)

Definition at line 1563 of file class.c.

Referenced by special_singleton_class_of().

Function Documentation

◆ add_refined_method_entry_i()

static enum rb_id_table_iterator_result add_refined_method_entry_i ( ID  key,
VALUE  value,
void *  data 
)
static

Definition at line 876 of file class.c.

References ID_TABLE_CONTINUE, and rb_add_refined_method_entry().

Referenced by include_modules_at().

◆ boot_defclass()

static VALUE boot_defclass ( const char *  name,
VALUE  super 
)
static

Definition at line 535 of file class.c.

References rb_class_boot(), rb_cObject, rb_const_set(), rb_intern, and rb_name_class().

Referenced by Init_class_hierarchy().

◆ class_alloc()

static VALUE class_alloc ( VALUE  flags,
VALUE  klass 
)
static

Allocates a struct RClass for a new class.

Parameters
flagsinitial value for basic.flags of the returned class.
klassthe class of the returned class.
Returns
an uninitialized Class object.
Precondition
klass must refer Class class or an ancestor of Class.
(flags | T_CLASS) != 0
Postcondition
the returned class can safely be initialize 'd.
Note
this function is not Class::allocate.

Definition at line 163 of file class.c.

References FL_PROMOTED1, FL_WB_PROTECTED, NEWOBJ_OF, Qnil, rb_next_class_serial(), RCLASS_EXT, RCLASS_REFINED_CLASS, RCLASS_SERIAL, RCLASS_SET_ORIGIN(), RGENGC_WB_PROTECTED_CLASS, T_MASK, and ZALLOC.

Referenced by rb_class_boot(), rb_include_class_new(), rb_module_new(), rb_prepend_module(), and rb_singleton_class_clone_and_attach().

◆ class_detach_module_subclasses()

static void class_detach_module_subclasses ( VALUE  klass,
VALUE  arg 
)
static

Definition at line 139 of file class.c.

References rb_class_remove_from_module_subclasses().

Referenced by rb_class_detach_module_subclasses().

◆ class_detach_subclasses()

static void class_detach_subclasses ( VALUE  klass,
VALUE  arg 
)
static

Definition at line 127 of file class.c.

References rb_class_remove_from_super_subclasses().

Referenced by rb_class_detach_subclasses().

◆ class_init_copy_check()

static void class_init_copy_check ( VALUE  clone,
VALUE  orig 
)
static

Definition at line 299 of file class.c.

References FL_SINGLETON, FL_TEST, rb_cBasicObject, rb_eTypeError, rb_raise(), and RCLASS_SUPER.

Referenced by rb_mod_init_copy().

◆ class_instance_method_list()

static VALUE class_instance_method_list ( int  argc,
const VALUE argv,
VALUE  mod,
int  obj,
int(*)(st_data_t, st_data_t, st_data_t func 
)
static

◆ clone_const()

static int clone_const ( ID  key,
const rb_const_entry_t ce,
struct clone_const_arg arg 
)
static

◆ clone_const_i()

static enum rb_id_table_iterator_result clone_const_i ( ID  key,
VALUE  value,
void *  data 
)
static

Definition at line 293 of file class.c.

References clone_const().

Referenced by rb_mod_init_copy(), and rb_singleton_class_clone_and_attach().

◆ clone_method()

static void clone_method ( VALUE  old_klass,
VALUE  new_klass,
ID  mid,
const rb_method_entry_t me 
)
static

◆ clone_method_i()

static enum rb_id_table_iterator_result clone_method_i ( ID  key,
VALUE  value,
void *  data 
)
static

◆ ensure_includable()

static void ensure_includable ( VALUE  klass,
VALUE  module 
)
static

◆ include_modules_at()

static int include_modules_at ( const VALUE  klass,
VALUE  c,
VALUE  module,
int  search_super 
)
static

◆ Init_class_hierarchy()

void Init_class_hierarchy ( void  )

◆ InitVM_Object()

void InitVM_Object ( void  )

Initializes the world of objects and classes.

At first, the function bootstraps the class hierarchy. It initializes the most fundamental classes and their metaclasses.

  • BasicObject
  • Object
  • Module
  • Class After the bootstrap step, the class hierarchy becomes as the following diagram.
boottime-classes.png

Then, the function defines classes, modules and methods as usual.

Definition at line 3407 of file object.c.

References CLASS_OF, false_and(), false_or(), false_to_s(), false_xor(), Init_class_hierarchy(), nil_inspect(), nil_to_a(), nil_to_f(), nil_to_h(), nil_to_i(), nil_to_s(), Qfalse, Qnil, Qtrue, rb_any_to_s(), rb_cBasicObject, rb_cClass, rb_cData, rb_cFalseClass, rb_class_allocate_instance(), rb_class_inherited_p(), rb_class_initialize(), rb_class_instance_methods(), rb_class_new_instance(), rb_class_private_instance_methods(), rb_class_protected_instance_methods(), rb_class_public_instance_methods(), rb_class_s_alloc(), rb_class_superclass(), rb_cModule, rb_cNilClass, rb_cObject, rb_cTrueClass, rb_define_alias(), rb_define_alloc_func(), rb_define_class(), rb_define_global_const(), rb_define_global_function(), rb_define_method(), rb_define_module(), rb_define_private_method(), rb_deprecate_constant(), rb_equal(), rb_f_array(), rb_f_float(), rb_f_hash(), rb_f_integer(), rb_f_sprintf(), rb_f_string(), rb_false(), rb_include_module(), rb_mKernel, rb_mod_ancestors(), rb_mod_attr(), rb_mod_attr_accessor(), rb_mod_attr_reader(), rb_mod_attr_writer(), rb_mod_class_variables(), rb_mod_cmp(), rb_mod_const_defined(), rb_mod_const_get(), rb_mod_const_missing(), rb_mod_const_set(), rb_mod_constants(), rb_mod_cvar_defined(), rb_mod_cvar_get(), rb_mod_cvar_set(), rb_mod_deprecate_constant(), rb_mod_eqq(), rb_mod_freeze(), rb_mod_ge(), rb_mod_gt(), rb_mod_include_p(), rb_mod_included_modules(), rb_mod_init_copy(), rb_mod_initialize(), rb_mod_initialize_clone(), rb_mod_lt(), rb_mod_name(), rb_mod_private_constant(), rb_mod_public_constant(), rb_mod_remove_const(), rb_mod_remove_cvar(), rb_mod_singleton_p(), rb_mod_to_s(), rb_module_s_alloc(), rb_obj_alloc(), rb_obj_class(), rb_obj_clone2(), rb_obj_cmp(), rb_obj_dummy(), rb_obj_dup(), rb_obj_equal(), rb_obj_freeze(), rb_obj_frozen_p(), rb_obj_hash(), rb_obj_init_copy(), rb_obj_init_dup_clone(), rb_obj_inspect(), rb_obj_instance_variables, rb_obj_is_instance_of(), rb_obj_is_kind_of(), rb_obj_itself(), rb_obj_ivar_defined(), rb_obj_ivar_get(), rb_obj_ivar_set(), rb_obj_match(), rb_obj_methods(), rb_obj_not(), rb_obj_not_equal(), rb_obj_not_match(), rb_obj_private_methods(), rb_obj_protected_methods(), rb_obj_public_methods(), rb_obj_remove_instance_variable(), rb_obj_singleton_class(), rb_obj_singleton_methods(), rb_obj_taint(), rb_obj_tainted(), rb_obj_tap(), rb_obj_trust(), rb_obj_untaint(), rb_obj_untrust(), rb_obj_untrusted(), rb_true(), rb_undef_alloc_func(), rb_undef_method(), true_and(), true_or(), true_to_s(), and true_xor().

◆ ins_methods_i()

static int ins_methods_i ( st_data_t  name,
st_data_t  type,
st_data_t  ary 
)
static

◆ ins_methods_priv_i()

static int ins_methods_priv_i ( st_data_t  name,
st_data_t  type,
st_data_t  ary 
)
static

◆ ins_methods_prot_i()

static int ins_methods_prot_i ( st_data_t  name,
st_data_t  type,
st_data_t  ary 
)
static

◆ ins_methods_pub_i()

static int ins_methods_pub_i ( st_data_t  name,
st_data_t  type,
st_data_t  ary 
)
static

◆ ins_methods_push()

static void ins_methods_push ( st_data_t  name,
st_data_t  ary 
)
static

Definition at line 1101 of file class.c.

References ID2SYM, and rb_ary_push().

Referenced by ins_methods_i(), ins_methods_priv_i(), ins_methods_prot_i(), and ins_methods_pub_i().

◆ make_metaclass()

static VALUE make_metaclass ( VALUE  klass)
inlinestatic

Creates a metaclass of klass.

Parameters
klassa class
Returns
created metaclass for the class
Precondition
klass is a Class object
klass has no singleton class.
Postcondition
the class of klass is the returned class.
the returned class is meta^(n+1)-class when klass is a meta^(n)-klass for n >= 0

Definition at line 486 of file class.c.

References ENSURE_EIGENCLASS, FL_SET, FL_SINGLETON, META_CLASS_OF_CLASS_CLASS_P, METACLASS_OF, OBJ_INFECT, Qundef, rb_cClass, rb_class_boot(), rb_singleton_class_attached(), RB_TYPE_P, RCLASS_SET_SUPER(), RCLASS_SUPER, SET_METACLASS_OF, and T_ICLASS.

Referenced by rb_make_metaclass().

◆ make_singleton_class()

static VALUE make_singleton_class ( VALUE  obj)
inlinestatic

Creates a singleton class for obj.

Precondition
obj must not a immediate nor a special const.
obj must not a Class object.
obj has no singleton class.

Definition at line 520 of file class.c.

References FL_SET, FL_SINGLETON, METACLASS_OF, rb_class_boot(), rb_class_real(), rb_singleton_class_attached(), RBASIC, RBASIC_SET_CLASS, and SET_METACLASS_OF.

Referenced by rb_make_metaclass().

◆ method_entry_i()

static enum rb_id_table_iterator_result method_entry_i ( ID  key,
VALUE  value,
void *  data 
)
static

◆ move_refined_method()

static enum rb_id_table_iterator_result move_refined_method ( ID  key,
VALUE  value,
void *  data 
)
static

◆ rb_check_inheritable()

void rb_check_inheritable ( VALUE  super)

Ensures a class can be derived from super.

Parameters
supera reference to an object.
Exceptions
TypeErrorif super is not a Class or super is a singleton class.

Definition at line 220 of file class.c.

References FL_SINGLETON, PRIsVALUE, rb_cClass, rb_eTypeError, rb_obj_class(), rb_raise(), RB_TYPE_P, RBASIC, and T_CLASS.

Referenced by rb_class_initialize(), and rb_class_new().

◆ rb_class_boot()

VALUE rb_class_boot ( VALUE  super)

A utility function that wraps class_alloc.

allocates a class and initializes safely.

Parameters
supera class from which the new class derives.
Returns
a class object.
Precondition
super must be a class.
Postcondition
the metaclass of the new class is Class.

Definition at line 201 of file class.c.

References class_alloc(), OBJ_INFECT, rb_cClass, RCLASS_M_TBL_INIT(), RCLASS_SET_SUPER(), and T_CLASS.

Referenced by boot_defclass(), make_metaclass(), make_singleton_class(), rb_class_new(), and rb_class_s_alloc().

◆ rb_class_detach_module_subclasses()

void rb_class_detach_module_subclasses ( VALUE  klass)

Definition at line 145 of file class.c.

References class_detach_module_subclasses(), Qnil, and rb_class_foreach_subclass().

Referenced by obj_free().

◆ rb_class_detach_subclasses()

void rb_class_detach_subclasses ( VALUE  klass)

Definition at line 133 of file class.c.

References class_detach_subclasses(), Qnil, and rb_class_foreach_subclass().

Referenced by obj_free().

◆ rb_class_foreach_subclass()

void rb_class_foreach_subclass ( VALUE  klass,
void(*)(VALUE, VALUE f,
VALUE  arg 
)

◆ rb_class_inherited()

VALUE rb_class_inherited ( VALUE  super,
VALUE  klass 
)

Calls Class::inherited.

Parameters
superA class which will be called #inherited. NULL means Object class.
klassA Class object which derived from super
Returns
the value Class::inherited's returns
Precondition
Each of super and klass must be a Class object.

Definition at line 620 of file class.c.

References CONST_ID, rb_cObject, and rb_funcall().

Referenced by anonymous_struct(), rb_class_initialize(), rb_define_class(), and rb_define_class_id_under().

◆ rb_class_instance_methods()

VALUE rb_class_instance_methods ( int  argc,
const VALUE argv,
VALUE  mod 
)

Definition at line 1241 of file class.c.

References class_instance_method_list(), and ins_methods_i().

Referenced by InitVM_Object().

◆ rb_class_new()

VALUE rb_class_new ( VALUE  super)

Creates a new class.

Parameters
supera class from which the new class derives.
Exceptions
TypeErrorsuper is not inheritable.
TypeErrorsuper is the Class class.

Definition at line 242 of file class.c.

References Check_Type, rb_check_inheritable(), rb_class_boot(), and T_CLASS.

Referenced by anonymous_struct(), Init_IO(), Init_VM(), and rb_define_class_id().

◆ rb_class_private_instance_methods()

VALUE rb_class_private_instance_methods ( int  argc,
const VALUE argv,
VALUE  mod 
)

Definition at line 1279 of file class.c.

References class_instance_method_list(), and ins_methods_priv_i().

Referenced by InitVM_Object().

◆ rb_class_protected_instance_methods()

VALUE rb_class_protected_instance_methods ( int  argc,
const VALUE argv,
VALUE  mod 
)

Definition at line 1256 of file class.c.

References class_instance_method_list(), and ins_methods_prot_i().

Referenced by InitVM_Object().

◆ rb_class_public_instance_methods()

VALUE rb_class_public_instance_methods ( int  argc,
const VALUE argv,
VALUE  mod 
)

Definition at line 1294 of file class.c.

References class_instance_method_list(), and ins_methods_pub_i().

Referenced by InitVM_Object().

◆ rb_class_remove_from_module_subclasses()

void rb_class_remove_from_module_subclasses ( VALUE  klass)

◆ rb_class_remove_from_super_subclasses()

void rb_class_remove_from_super_subclasses ( VALUE  klass)

◆ rb_class_subclass_add()

void rb_class_subclass_add ( VALUE  super,
VALUE  klass 
)

Definition at line 36 of file class.c.

References ALLOC, rb_subclass_entry::klass, rb_subclass_entry::next, NULL, Qundef, and RCLASS_EXT.

Referenced by RCLASS_SET_SUPER().

◆ rb_define_class()

VALUE rb_define_class ( const char *  name,
VALUE  super 
)

Defines a top-level class.

Parameters
namename of the class
supera class from which the new class will derive.
Returns
the created class
Exceptions
TypeErrorif the constant name name is already taken but the constant is not a Class.
TypeErrorif the class is already defined but the class can not be reopened because its superclass is not super.
ArgumentErrorif the super is NULL.
Postcondition
top-level constant named name refers the returned class.
Note
if a class named name is already defined and its superclass is super, the function just returns the defined class.

Definition at line 646 of file class.c.

References id, PRIsVALUE, rb_class_inherited(), rb_class_real(), rb_cObject, rb_const_defined(), rb_const_get(), rb_const_set(), rb_define_class_id(), rb_eArgError, rb_eTypeError, rb_intern, rb_name_class(), rb_obj_class(), rb_raise(), RB_TYPE_P, rb_vm_add_root_module(), RCLASS_SUPER, and T_CLASS.

Referenced by Init_Array(), Init_bigdecimal(), Init_Binding(), Init_Complex(), Init_Cont(), Init_date_core(), Init_dbm(), Init_Dir(), Init_Encoding(), Init_Exception(), Init_File(), Init_gdbm(), Init_Hash(), Init_IO(), Init_Numeric(), Init_pathname(), Init_Proc(), Init_Rational(), Init_Regexp(), Init_sdbm(), Init_socket(), Init_String(), Init_stringio(), Init_strscan(), Init_Thread(), Init_thread_sync(), Init_Time(), Init_VM(), Init_vm_eval(), Init_vm_trace(), Init_win32ole(), Init_win32ole_error(), Init_win32ole_event(), Init_win32ole_method(), Init_win32ole_param(), Init_win32ole_record(), Init_win32ole_type(), Init_win32ole_typelib(), Init_win32ole_variable(), Init_win32ole_variant(), InitVM_Enumerator(), InitVM_escape(), InitVM_Object(), InitVM_Random(), InitVM_Struct(), parser_compile_error(), rsock_init_addrinfo(), rsock_init_basicsocket(), rsock_init_ipsocket(), rsock_init_socket_init(), rsock_init_sockssocket(), rsock_init_tcpserver(), rsock_init_tcpsocket(), rsock_init_udpsocket(), rsock_init_unixserver(), rsock_init_unixsocket(), ruby_Init_Continuation_body(), and struct_define_without_accessor().

◆ rb_define_class_id()

VALUE rb_define_class_id ( ID  id,
VALUE  super 
)

Defines a new class.

Parameters
idignored
superA class from which the new class will derive. NULL means Object class.
Returns
the created class
Exceptions
TypeErrorif super is not a Class object.
Note
the returned class will not be associated with id. You must explicitly set a class name if necessary.

Definition at line 599 of file class.c.

References rb_class_new(), rb_cObject, rb_make_metaclass(), and RBASIC.

Referenced by rb_define_class(), and rb_define_class_id_under().

◆ rb_define_class_id_under()

VALUE rb_define_class_id_under ( VALUE  outer,
ID  id,
VALUE  super 
)

Defines a class under the namespace of outer.

Parameters
outera class which contains the new class.
idname of the new class
supera class from which the new class will derive. NULL means Object class.
Returns
the created class
Exceptions
TypeErrorif the constant name name is already taken but the constant is not a Class.
TypeErrorif the class is already defined but the class can not be reopened because its superclass is not super.
Postcondition
top-level constant named name refers the returned class.
Note
if a class named name is already defined and its superclass is super, the function just returns the defined class.

Definition at line 716 of file class.c.

References PRIsVALUE, rb_class_inherited(), rb_class_path(), rb_class_real(), rb_const_defined_at(), rb_const_get_at(), rb_const_set(), rb_define_class_id(), rb_eArgError, rb_eTypeError, rb_gc_register_mark_object(), rb_id2str, rb_obj_class(), rb_raise(), rb_set_class_path_string(), RB_TYPE_P, RCLASS_SUPER, and T_CLASS.

Referenced by new_struct(), and rb_define_class_under().

◆ rb_define_class_under()

VALUE rb_define_class_under ( VALUE  outer,
const char *  name,
VALUE  super 
)

Defines a class under the namespace of outer.

Parameters
outera class which contains the new class.
namename of the new class
supera class from which the new class will derive. NULL means Object class.
Returns
the created class
Exceptions
TypeErrorif the constant name name is already taken but the constant is not a Class.
TypeErrorif the class is already defined but the class can not be reopened because its superclass is not super.
Postcondition
top-level constant named name refers the returned class.
Note
if a class named name is already defined and its superclass is super, the function just returns the defined class.

Definition at line 693 of file class.c.

References rb_define_class_id_under(), and rb_intern.

Referenced by exp1(), Init_bubblebabble(), Init_Complex(), Init_cparse(), Init_digest(), Init_Exception(), Init_fiddle(), Init_fiddle_closure(), Init_fiddle_function(), Init_fiddle_handle(), Init_fiddle_pointer(), Init_File(), Init_GC(), Init_generator(), Init_IO(), Init_ISeq(), Init_md5(), Init_objspace(), Init_openssl(), Init_ossl_asn1(), Init_ossl_bn(), Init_ossl_cipher(), Init_ossl_config(), Init_ossl_dh(), Init_ossl_digest(), Init_ossl_dsa(), Init_ossl_engine(), Init_ossl_hmac(), Init_ossl_ns_spki(), Init_ossl_ocsp(), Init_ossl_pkcs12(), Init_ossl_pkcs5(), Init_ossl_pkcs7(), Init_ossl_pkey(), Init_ossl_rand(), Init_ossl_rsa(), Init_ossl_ssl(), Init_ossl_ssl_session(), Init_ossl_x509attr(), Init_ossl_x509cert(), Init_ossl_x509crl(), Init_ossl_x509ext(), Init_ossl_x509name(), Init_ossl_x509req(), Init_ossl_x509revoked(), Init_ossl_x509store(), Init_parser(), Init_psych_emitter(), Init_psych_parser(), Init_psych_to_ruby(), Init_psych_yaml_tree(), Init_pty(), Init_Rational(), Init_rmd160(), Init_sha1(), Init_strscan(), Init_thread_sync(), Init_vm_backtrace(), Init_zlib(), InitVM_Enumerator(), InitVM_process(), InitVM_transcode(), rb_struct_define_under(), rsock_init_ancdata(), rsock_init_sockifaddr(), rsock_init_sockopt(), set_syserr(), and struct_define_without_accessor().

◆ rb_define_module()

VALUE rb_define_module ( const char *  name)

◆ rb_define_module_id()

VALUE rb_define_module_id ( ID  id)

Definition at line 757 of file class.c.

References rb_module_new(), and rb_name_class().

Referenced by rb_define_module(), and rb_define_module_id_under().

◆ rb_define_module_id_under()

VALUE rb_define_module_id_under ( VALUE  outer,
ID  id 
)

◆ rb_define_module_under()

VALUE rb_define_module_under ( VALUE  outer,
const char *  name 
)

◆ rb_freeze_singleton_class()

void rb_freeze_singleton_class ( VALUE  x)

Definition at line 1638 of file class.c.

References FL_FREEZE, FL_SINGLETON, FL_TEST, OBJ_FREEZE_RAW, RBASIC, RBASIC_CLASS, and RCLASS_ORIGIN.

Referenced by rb_obj_freeze_inline().

◆ rb_include_class_new()

VALUE rb_include_class_new ( VALUE  module,
VALUE  super 
)

◆ rb_include_module()

void rb_include_module ( VALUE  klass,
VALUE  module 
)

◆ rb_make_metaclass()

VALUE rb_make_metaclass ( VALUE  obj,
VALUE  unused 
)

Creates a new singleton class for an object.

Precondition
obj has no singleton class.
Note
DO NOT USE the function in an extension libraries. Use rb_singleton_class.
Parameters
objAn object.
unusedignored.
Returns
The singleton class of the object.

Definition at line 577 of file class.c.

References BUILTIN_TYPE, make_metaclass(), make_singleton_class(), and T_CLASS.

Referenced by anonymous_struct(), rb_class_initialize(), rb_define_class_id(), and singleton_class_of().

◆ rb_mod_ancestors()

VALUE rb_mod_ancestors ( VALUE  mod)

◆ rb_mod_include_p()

VALUE rb_mod_include_p ( VALUE  mod,
VALUE  mod2 
)

Definition at line 1053 of file class.c.

References BUILTIN_TYPE, Check_Type, Qfalse, Qtrue, RBASIC, RCLASS_SUPER, T_ICLASS, and T_MODULE.

Referenced by InitVM_Object().

◆ rb_mod_included_modules()

VALUE rb_mod_included_modules ( VALUE  mod)

Definition at line 1017 of file class.c.

References BUILTIN_TYPE, rb_ary_new(), rb_ary_push(), RB_TYPE_P, RBASIC, RCLASS_ORIGIN, RCLASS_SUPER, T_ICLASS, and T_MODULE.

Referenced by InitVM_Object().

◆ rb_mod_init_copy()

VALUE rb_mod_init_copy ( VALUE  clone,
VALUE  orig 
)

◆ rb_module_add_to_subclasses_list()

static void rb_module_add_to_subclasses_list ( VALUE  module,
VALUE  iclass 
)
static

Definition at line 57 of file class.c.

References ALLOC, rb_subclass_entry::klass, rb_subclass_entry::next, NULL, and RCLASS_EXT.

Referenced by include_modules_at().

◆ rb_module_new()

VALUE rb_module_new ( void  )

◆ rb_obj_methods()

VALUE rb_obj_methods ( int  argc,
const VALUE argv,
VALUE  obj 
)

◆ rb_obj_private_methods()

VALUE rb_obj_private_methods ( int  argc,
const VALUE argv,
VALUE  obj 
)

Definition at line 1364 of file class.c.

References class_instance_method_list(), CLASS_OF, and ins_methods_priv_i().

Referenced by InitVM_Object().

◆ rb_obj_protected_methods()

VALUE rb_obj_protected_methods ( int  argc,
const VALUE argv,
VALUE  obj 
)

Definition at line 1349 of file class.c.

References class_instance_method_list(), CLASS_OF, and ins_methods_prot_i().

Referenced by InitVM_Object().

◆ rb_obj_public_methods()

VALUE rb_obj_public_methods ( int  argc,
const VALUE argv,
VALUE  obj 
)

Definition at line 1379 of file class.c.

References class_instance_method_list(), CLASS_OF, and ins_methods_pub_i().

Referenced by InitVM_Object().

◆ rb_obj_singleton_methods()

VALUE rb_obj_singleton_methods ( int  argc,
const VALUE argv,
VALUE  obj 
)

◆ rb_prepend_module()

void rb_prepend_module ( VALUE  klass,
VALUE  module 
)

◆ rb_singleton_class()

VALUE rb_singleton_class ( VALUE  obj)

Returns the singleton class of obj.

Creates it if necessary.

Parameters
objan arbitrary object.
Exceptions
TypeErrorif obj is a Integer or a Symbol.
Returns
the singleton class.
Postcondition
obj has its own singleton class.
if 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.
Note
a new singleton class will be created if obj does not have it.
the singleton classes for nil, true and false are: NilClass, TrueClass and FalseClass.

Definition at line 1689 of file class.c.

References ENSURE_EIGENCLASS, RB_TYPE_P, singleton_class_of(), and T_CLASS.

Referenced by Init_date_core(), Init_eval(), Init_eval_method(), Init_nkf(), Init_Proc(), Init_Time(), Init_top_self(), Init_VM(), InitVM_process(), InitVM_resolv(), num_sadded(), r_object0(), rb_extend_object(), rb_mod_define_method(), rb_mod_modfunc(), rb_mod_private_method(), rb_mod_public_method(), rb_obj_define_method(), rb_obj_singleton_class(), singleton_class_for_eval(), and vm_define_method().

◆ rb_singleton_class_attached()

void rb_singleton_class_attached ( VALUE  klass,
VALUE  obj 
)

Attach a object to a singleton class.

Precondition
klass is the singleton class of obj.

Definition at line 421 of file class.c.

References FL_SINGLETON, FL_TEST, id_attached, rb_class_ivar_set(), RCLASS_IV_TBL, and st_init_numtable.

Referenced by make_metaclass(), make_singleton_class(), rb_clone_setup(), rb_mod_init_copy(), rb_obj_clone2(), and rb_singleton_class_clone_and_attach().

◆ rb_singleton_class_clone()

VALUE rb_singleton_class_clone ( VALUE  obj)

◆ rb_singleton_class_clone_and_attach()

VALUE rb_singleton_class_clone_and_attach ( VALUE  obj,
VALUE  attach 
)

◆ rb_singleton_class_get()

VALUE rb_singleton_class_get ( VALUE  obj)

Returns the singleton class of obj, or nil if obj is not a singleton object.

Parameters
objan arbitrary object.
Returns
the singleton class or nil.

Definition at line 1658 of file class.c.

References FL_SINGLETON, FL_TEST, id_attached, Qnil, rb_ivar_get(), rb_special_singleton_class(), RBASIC, and SPECIAL_CONST_P.

Referenced by rb_obj_singleton_method().

◆ rb_singleton_class_has_metaclass_p()

static int rb_singleton_class_has_metaclass_p ( VALUE  sklass)
static

Definition at line 444 of file class.c.

References id_attached, METACLASS_OF, and rb_attr_get().

Referenced by rb_singleton_class_internal_p().

◆ rb_singleton_class_internal_p()

int rb_singleton_class_internal_p ( VALUE  sklass)

Definition at line 450 of file class.c.

References id_attached, rb_attr_get(), rb_singleton_class_has_metaclass_p(), RB_TYPE_P, and T_CLASS.

Referenced by internal_object_p().

◆ rb_special_singleton_class()

VALUE rb_special_singleton_class ( VALUE  obj)

Definition at line 1579 of file class.c.

References special_singleton_class_of().

Referenced by rb_singleton_class_get(), and singleton_class_for_eval().

◆ RCLASS_M_TBL_INIT()

static void RCLASS_M_TBL_INIT ( VALUE  c)
static

◆ singleton_class_of()

static VALUE singleton_class_of ( VALUE  obj)
static

Returns the singleton class of obj. Creates it if necessary.

Note
DO NOT expose the returned singleton class to outside of class.c. Use rb_singleton_class instead for consistency of the metaclass hierarchy.

Definition at line 1594 of file class.c.

References BUILTIN_TYPE, FIXNUM_P, FL_SINGLETON, FL_TAINT, FL_TEST, FL_TEST_RAW, FL_UNSET, FLONUM_P, id_attached, NIL_P, OBJ_TAINT, OBJ_TAINTED, rb_bug(), rb_eTypeError, RB_FL_SET_RAW, rb_ivar_get(), rb_make_metaclass(), RB_OBJ_FROZEN_RAW, rb_raise(), RBASIC, RCLASS_SERIAL, RSTRING_FSTR, SPECIAL_CONST_P, special_singleton_class_of(), STATIC_SYM_P, T_BIGNUM, T_FLOAT, T_STRING, and T_SYMBOL.

Referenced by rb_define_singleton_method(), and rb_singleton_class().

◆ special_singleton_class_of()

static VALUE special_singleton_class_of ( VALUE  obj)
inlinestatic