Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

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)
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)
void | rb_class_detach_subclasses (VALUE klass)
void | rb_class_detach_module_subclasses (VALUE klass)
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...
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...
int | rb_singleton_class_internal_p (VALUE sklass)
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...
MJIT_FUNC_EXPORTED 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)
void | rb_include_module (VALUE klass, VALUE module)
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)
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)
VALUE | rb_special_singleton_class (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 | rb_class_modify_check (VALUE klass)
| Asserts that klass is not a frozen class. More...
void | rb_extend_object (VALUE obj, VALUE module)
| Extend the object with the module. 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 477 of file class.c.

## ◆ HAVE_METACLASS_P

#define HAVE_METACLASS_P | ( |  | k | ) |

Value:
(FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
rb_singleton_class_has_metaclass_p(k))

whether k has a metaclass

Return values

  1 | if k has a metaclass
  0 | otherwise

Definition at line 466 of file class.c.

## ◆ id_attached

#define id_attached id__attached__

Definition at line 33 of file class.c.

## ◆ 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

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

Definition at line 446 of file class.c.

## ◆ METACLASS_OF

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

Definition at line 438 of file class.c.

## ◆ SET_METACLASS_OF

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

Definition at line 439 of file class.c.

## ◆ SPECIAL_SINGLETON

#define SPECIAL_SINGLETON | ( |  | x,
|  |  | c
| ) |  |

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

Definition at line 1605 of file class.c.

## Function Documentation

## ◆ Init_class_hierarchy()

void Init_class_hierarchy | ( | void |  | ) |

Definition at line 549 of file class.c.

References rb_cBasicObject.

## ◆ rb_check_inheritable()

void rb_check_inheritable | ( | VALUE | super | ) |

Ensures a class can be derived from super.

Parameters

  super | a reference to an object.

Exceptions

  TypeError | if super is not a Class or super is a singleton class.

Definition at line 219 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_new().

## ◆ rb_class_boot()

VALUE rb_class_boot | ( | VALUE | super | ) |

A utility function that wraps class_alloc.

allocates a class and initializes safely.

Parameters

  super | a 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 klass.

Referenced by rb_class_new().

## ◆ rb_class_detach_module_subclasses()

void rb_class_detach_module_subclasses | ( | VALUE | klass | ) |

Definition at line 145 of file class.c.

References klass, and rb_class_foreach_subclass().

## ◆ rb_class_detach_subclasses()

void rb_class_detach_subclasses | ( | VALUE | klass | ) |

Definition at line 133 of file class.c.

References klass, and rb_class_foreach_subclass().

## ◆ rb_class_foreach_subclass()

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

Definition at line 113 of file class.c.

References arg, f, rb_subclass_entry::klass, klass, rb_subclass_entry::next, and RCLASS_EXT.

Referenced by rb_class_detach_module_subclasses(), and rb_class_detach_subclasses().

## ◆ rb_class_inherited()

MJIT_FUNC_EXPORTED VALUE rb_class_inherited | ( | VALUE | super,
|  | VALUE | klass
| ) |  |

Calls Class::inherited.

Parameters

  super | A class which will be called #inherited. NULL means Object class.
  klass | A 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 623 of file class.c.

References CONST_ID, klass, rb_cObject, and rb_funcall.

Referenced by 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 1272 of file class.c.

## ◆ rb_class_modify_check()

void rb_class_modify_check | ( | VALUE | klass | ) |

Asserts that klass is not a frozen class.

Parameters

  [in] | klass | a `Module` object

Exceptions

  RuntimeError | if klass is not a class or frozen.

Definition at line 437 of file eval.c.

References BUILTIN_TYPE, Check_Type, FL_SINGLETON, FL_TEST, id__attached__, klass, OBJ_FROZEN, PRIsVALUE, rb_frozen_error_raise(), rb_ivar_get(), SPECIAL_CONST_P, T_CLASS, T_ICLASS, and T_MODULE.

Referenced by rb_alias(), rb_deprecate_constant(), and rb_undef().

## ◆ rb_class_new()

VALUE rb_class_new | ( | VALUE | super | ) |

Creates a new class.

Parameters

  super | a class from which the new class derives.

Exceptions

  TypeError | super is not inheritable.
  TypeError | super is the Class class.

Definition at line 241 of file class.c.

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

Referenced by 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 1310 of file class.c.

## ◆ rb_class_protected_instance_methods()

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

Definition at line 1287 of file class.c.

## ◆ rb_class_public_instance_methods()

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

Definition at line 1325 of file class.c.

## ◆ rb_class_remove_from_module_subclasses()

void rb_class_remove_from_module_subclasses | ( | VALUE | klass | ) |

Definition at line 94 of file class.c.

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

## ◆ rb_class_remove_from_super_subclasses()

void rb_class_remove_from_super_subclasses | ( | VALUE | klass | ) |

Definition at line 76 of file class.c.

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

## ◆ 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, klass, rb_subclass_entry::next, NULL, Qundef, and RCLASS_EXT.

## ◆ rb_define_class()

VALUE rb_define_class | ( | const char * | name,
|  | VALUE | super
| ) |  |

Defines a top-level class.

Parameters

  name | name of the class
  super | a class from which the new class will derive.

Returns
  the created class

Exceptions

  TypeError | if the constant name name is already taken but the constant is not a `Class`.
  TypeError | if the class is already defined but the class can not be reopened because its superclass is not super.
  ArgumentError | if 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 649 of file class.c.

References id, klass, name, 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_obj_class(), rb_raise(), RB_TYPE_P, rb_vm_add_root_module(), RCLASS_SUPER, and T_CLASS.

Referenced by Init_Array(), Init_Binding(), Init_Dir(), Init_Encoding(), Init_Exception(), Init_File(), Init_IO(), Init_monitor(), Init_Proc(), Init_Regexp(), Init_socket(), Init_String(), Init_stringio(), Init_VM(), Init_win32ole_error(), Init_win32ole_method(), Init_win32ole_param(), Init_win32ole_record(), Init_win32ole_type(), Init_win32ole_typelib(), Init_win32ole_variable(), Init_win32ole_variant(), InitVM_Struct(), 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(), and rsock_init_unixsocket().

## ◆ rb_define_class_id()

VALUE rb_define_class_id | ( | ID | id,
|  | VALUE | super
| ) |  |

Defines a new class.

Parameters

  id | ignored
  super | A class from which the new class will derive. NULL means `Object` class.

Returns
  the created class

Exceptions

  TypeError | if 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 602 of file class.c.

References klass, 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

  outer | a class which contains the new class.
  id | name of the new class
  super | a class from which the new class will derive. NULL means `Object` class.

Returns
  the created class

Exceptions

  TypeError | if the constant name name is already taken but the constant is not a `Class`.
  TypeError | if 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 721 of file class.c.

References klass, 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, rb_vm_add_root_module(), RCLASS_SUPER, and T_CLASS.

Referenced by 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

  outer | a class which contains the new class.
  name | name of the new class
  super | a class from which the new class will derive. NULL means `Object` class.

Returns
  the created class

Exceptions

  TypeError | if the constant name name is already taken but the constant is not a `Class`.
  TypeError | if 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 698 of file class.c.

References name, rb_define_class_id_under(), and rb_intern.

Referenced by exp2(), Init_cparse(), Init_fiddle(), Init_fiddle_closure(), Init_fiddle_function(), Init_fiddle_handle(), Init_ISeq(), Init_ossl_asn1(), Init_ossl_bn(), Init_ossl_cipher(), Init_ossl_config(), Init_ossl_dh(), Init_ossl_digest(), Init_ossl_dsa(), Init_ossl_ec(), Init_ossl_engine(), Init_ossl_hmac(), Init_ossl_kdf(), Init_ossl_ns_spki(), Init_ossl_ocsp(), Init_ossl_pkcs12(), 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_x509req(), Init_ossl_x509revoked(), Init_ossl_x509store(), Init_psych_emitter(), Init_psych_parser(), Init_psych_to_ruby(), Init_psych_yaml_tree(), rsock_init_ancdata(), rsock_init_sockifaddr(), and rsock_init_sockopt().

## ◆ rb_define_module()

VALUE rb_define_module | ( | const char * | name | ) |

Definition at line 772 of file class.c.

References id, name, PRIsVALUE, rb_cObject, rb_const_defined(), rb_const_get(), rb_const_set(), rb_define_module_id(), rb_eTypeError, rb_gc_register_mark_object(), rb_intern, rb_obj_class(), rb_raise(), RB_TYPE_P, rb_vm_add_root_module(), and T_MODULE.

Referenced by exp2(), Init_Comparable(), Init_coverage(), Init_cparse(), Init_Enumerable(), Init_etc(), Init_fcntl(), Init_fiddle(), Init_fiddle_closure(), Init_File(), Init_GC(), Init_limits(), Init_marshal(), Init_md5(), Init_nkf(), Init_object_tracing(), Init_objspace(), Init_objspace_dump(), Init_openssl(), Init_ossl_asn1(), Init_ossl_bn(), Init_ossl_cipher(), Init_ossl_config(), Init_ossl_digest(), Init_ossl_engine(), Init_ossl_hmac(), Init_ossl_kdf(), Init_ossl_ns_spki(), Init_ossl_ocsp(), Init_ossl_pkcs12(), Init_ossl_pkcs7(), Init_ossl_pkey(), Init_ossl_rand(), Init_ossl_ssl(), Init_ossl_ssl_session(), Init_ossl_x509(), Init_ossl_x509attr(), Init_ossl_x509cert(), Init_ossl_x509crl(), Init_ossl_x509ext(), Init_ossl_x509req(), Init_ossl_x509revoked(), Init_ossl_x509store(), Init_psych(), Init_psych_emitter(), Init_psych_parser(), Init_psych_to_ruby(), Init_psych_yaml_tree(), Init_rmd160(), Init_sha1(), Init_signal(), Init_sizeof(), Init_zlib(), and InitVM_resolv().

## ◆ rb_define_module_id()

VALUE rb_define_module_id | ( | ID | id | ) |

Definition at line 766 of file class.c.

References rb_module_new().

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
| ) |  |

Definition at line 803 of file class.c.

References PRIsVALUE, rb_const_defined_at(), rb_const_get_at(), rb_const_set(), rb_define_module_id(), rb_eTypeError, rb_gc_register_mark_object(), rb_id2str, rb_obj_class(), rb_raise(), rb_set_class_path_string(), RB_TYPE_P, and T_MODULE.

Referenced by rb_define_module_under().

## ◆ rb_define_module_under()

VALUE rb_define_module_under | ( | VALUE | outer,
|  | const char * | name
| ) |  |

Definition at line 797 of file class.c.

References name, rb_define_module_id_under(), and rb_intern.

Referenced by Init_GC(), Init_ossl_dh(), Init_ossl_dsa(), Init_ossl_ec(), Init_ossl_ns_spki(), Init_ossl_ocsp(), Init_ossl_pkey(), Init_ossl_rand(), Init_ossl_rsa(), Init_ossl_ssl(), Init_ossl_ssl_session(), Init_ossl_x509(), Init_ossl_x509attr(), Init_ossl_x509cert(), Init_ossl_x509crl(), Init_ossl_x509ext(), Init_ossl_x509req(), Init_ossl_x509revoked(), Init_ossl_x509store(), Init_psych_to_ruby(), Init_psych_yaml_tree(), Init_win32ole_variant_m(), and InitVM_resolv().

## ◆ rb_extend_object()

void rb_extend_object | ( | VALUE | obj,
|  | VALUE | module
| ) |  |

Extend the object with the module.

Same as `Module#extend_object`.

Definition at line 1700 of file eval.c.

References obj, rb_include_module(), and rb_singleton_class().

Referenced by rb_eval_string_wrap(), rb_mod_syserr_fail(), and rb_mod_syserr_fail_str().

## ◆ rb_freeze_singleton_class()

void rb_freeze_singleton_class | ( | VALUE | x | ) |

Definition at line 1674 of file class.c.

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

## ◆ rb_include_class_new()

VALUE rb_include_class_new | ( | VALUE | module,
|  | VALUE | super
| ) |  |

Definition at line 825 of file class.c.

References klass.

## ◆ rb_include_module()

void rb_include_module | ( | VALUE | klass,
|  | VALUE | module
| ) |  |

Definition at line 869 of file class.c.

Referenced by Init_Array(), Init_Dir(), Init_stringio(), InitVM_Struct(), and rb_extend_object().

## ◆ rb_make_metaclass()

VALUE rb_make_metaclass | ( | VALUE | obj,
|  | VALUE | unused
| ) |  |

Definition at line 580 of file class.c.

References BUILTIN_TYPE, obj, and T_CLASS.

Referenced by rb_define_class_id().

## ◆ rb_mod_ancestors()

VALUE rb_mod_ancestors | ( | VALUE | mod | ) |

Definition at line 1099 of file class.c.

References BUILTIN_TYPE, klass, mod, rb_ary_new(), rb_ary_push(), RBASIC, RCLASS_ORIGIN, RCLASS_SUPER, and T_ICLASS.

## ◆ rb_mod_include_p()

VALUE rb_mod_include_p | ( | VALUE | mod,
|  | VALUE | mod2
| ) |  |

Definition at line 1067 of file class.c.

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

## ◆ rb_mod_included_modules()

VALUE rb_mod_included_modules | ( | VALUE | mod | ) |

Definition at line 1031 of file class.c.

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

## ◆ rb_mod_init_copy()

VALUE rb_mod_init_copy | ( | VALUE | clone,
|  | VALUE | orig
| ) |  |

Definition at line 313 of file class.c.

References FL_SET, RB_TYPE_P, RCLASS_CLONED, and T_CLASS.

## ◆ rb_module_new()

VALUE rb_module_new | ( | void |  | ) |

Definition at line 758 of file class.c.

Referenced by rb_define_module_id(), and rb_eval_string_wrap().

## ◆ rb_obj_methods()

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

Definition at line 1361 of file class.c.

References argc, argv, obj, rb_check_arity, rb_obj_singleton_methods(), and RTEST.

## ◆ rb_obj_private_methods()

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

Definition at line 1395 of file class.c.

## ◆ rb_obj_protected_methods()

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

Definition at line 1380 of file class.c.

## ◆ rb_obj_public_methods()

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

Definition at line 1410 of file class.c.

## ◆ rb_obj_singleton_methods()

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

Definition at line 1449 of file class.c.

References argc, argv, CLASS_OF, FL_SINGLETON, FL_TEST, klass, method_entry_arg::list, obj, rb_check_arity, rb_id_table_foreach(), rb_singleton_class(), RB_TYPE_P, RCLASS_M_TBL, RCLASS_ORIGIN, recur, method_entry_arg::recur, RTEST, st_init_numtable(), T_CLASS, and TRUE.

Referenced by rb_obj_methods().

## ◆ rb_prepend_module()

void rb_prepend_module | ( | VALUE | klass,
|  | VALUE | module
| ) |  |

Definition at line 999 of file class.c.

## ◆ rb_singleton_class()

VALUE rb_singleton_class | ( | VALUE | obj | ) |

Returns the singleton class of obj.

Creates it if necessary.

Parameters

  obj | an arbitrary object.

Exceptions

  TypeError | if 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 1725 of file class.c.

References klass.

Referenced by InitVM_resolv(), rb_extend_object(), and rb_obj_singleton_methods().

## ◆ 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 426 of file class.c.

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

## ◆ rb_singleton_class_clone()

VALUE rb_singleton_class_clone | ( | VALUE | obj | ) |

Definition at line 370 of file class.c.

References obj, Qundef, and rb_singleton_class_clone_and_attach().

## ◆ rb_singleton_class_clone_and_attach()

VALUE rb_singleton_class_clone_and_attach | ( | VALUE | obj,
|  | VALUE | attach
| ) |  |

Definition at line 376 of file class.c.

References FL_SINGLETON, FL_TEST, klass, obj, and RBASIC.

Referenced by rb_singleton_class_clone().

## ◆ 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

  obj | an arbitrary object.

Returns
  the singleton class or nil.

Definition at line 1694 of file class.c.

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

Referenced by rb_obj_singleton_method().

## ◆ rb_singleton_class_internal_p()

int rb_singleton_class_internal_p | ( | VALUE | sklass | ) |

Definition at line 455 of file class.c.

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

## ◆ rb_special_singleton_class()

VALUE rb_special_singleton_class | ( | VALUE | obj | ) |

Definition at line 1621 of file class.c.

Referenced by rb_singleton_class_get().

FL_TEST
#define FL_TEST(x, f)
Definition: ruby.h:1353
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.0.h:5742
METACLASS_OF
#define METACLASS_OF(k)
Definition: class.c:438
FL_SINGLETON
#define FL_SINGLETON
Definition: ruby.h:1278