Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

Macros | Functions | Variables
Classes and their hierarchy.

## Macros
#define | METACLASS_OF(k) RBASIC(k)->klass
#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 | VISI(x) ((x)&NOEX_MASK)
#define | VISI_CHECK(x, f) (VISI(x) == (f))
#define | SPECIAL_SINGLETON(x, c)

## Functions
static VALUE | class_alloc (VALUE flags, VALUE klass)
| Allocates a struct RClass for a new class. More...
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 NODE * | rewrite_cref_stack (NODE *node, VALUE old_klass, VALUE new_klass)
static void | clone_method (VALUE klass, ID mid, const rb_method_entry_t *me)
static int | clone_method_i (st_data_t key, st_data_t value, st_data_t data)
static int | clone_const (ID key, const rb_const_entry_t *ce, st_table *tbl)
static int | clone_const_i (st_data_t key, st_data_t value, st_data_t 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 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)
void | rb_include_module (VALUE klass, VALUE module)
static int | add_refined_method_entry_i (st_data_t key, st_data_t value, st_data_t data)
static int | move_refined_method (st_data_t key, st_data_t value, st_data_t 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 int | ins_methods_push (ID name, long type, VALUE ary, long visi)
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 int | method_entry_i (st_data_t key, st_data_t value, st_data_t data)
static VALUE | class_instance_method_list (int argc, VALUE *argv, VALUE mod, int obj, int(*func)(st_data_t, st_data_t, st_data_t))
VALUE | rb_class_instance_methods (int argc, VALUE *argv, VALUE mod)
VALUE | rb_class_protected_instance_methods (int argc, VALUE *argv, VALUE mod)
VALUE | rb_class_private_instance_methods (int argc, VALUE *argv, VALUE mod)
VALUE | rb_class_public_instance_methods (int argc, VALUE *argv, VALUE mod)
VALUE | rb_obj_methods (int argc, VALUE *argv, VALUE obj)
VALUE | rb_obj_protected_methods (int argc, VALUE *argv, VALUE obj)
VALUE | rb_obj_private_methods (int argc, VALUE *argv, VALUE obj)
VALUE | rb_obj_public_methods (int argc, VALUE *argv, VALUE obj)
VALUE | rb_obj_singleton_methods (int argc, 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)
VALUE | rb_singleton_class (VALUE obj)
| Returns the singleton class of obj. More...
void | Init_Object (void)
| Initializes the world of objects and classes. More...

## Variables
st_table * | rb_class_tbl
static ID | id_attached

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

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

Referenced by make_metaclass(), and rb_singleton_class().

#define HAVE_METACLASS_P | ( |  | k | ) |

Value:
(FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
rb_ivar_get(METACLASS_OF(k), id_attached) == (k))
id_attached
static ID id_attached
Definition: class.c:35
FL_TEST
#define FL_TEST(x, f)
rb_ivar_get
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1116
METACLASS_OF
#define METACLASS_OF(k)
Definition: class.c:301
FL_SINGLETON
#define FL_SINGLETON

whether k has a metaclass

Return values

  1 | if k has a metaclass
  0 | otherwise

Definition at line 315 of file class.c.

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

Referenced by make_metaclass().

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

Definition at line 301 of file class.c.

Referenced by make_metaclass(), and make_singleton_class().

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

Value:
do {\
if (obj == (x)) {\
return (c);\
}\
} while (0)
return
return
Definition: bigdecimal.c:5800
obj
static VALUE VALUE obj
Definition: tcltklib.c:3158
c
VpDivd * c
Definition: bigdecimal.c:1205
if
if(RB_TYPE_P(r, T_FLOAT))
Definition: bigdecimal.c:1186

Definition at line 1375 of file class.c.

Referenced by special_singleton_class_of().

#define VISI | ( |  | x | ) | ((x)&NOEX_MASK)

Definition at line 937 of file class.c.

Referenced by method_entry_i().

#define VISI_CHECK | ( |  | x,
|  |  | f
| ) |  | (VISI(x) == (f))

Definition at line 938 of file class.c.

## Function Documentation

static int add_refined_method_entry_i | ( | st_data_t | key,
|  | st_data_t | value,
|  | st_data_t | data
| ) |  |
| static

Definition at line 717 of file class.c.

References rb_add_refined_method_entry(), and ST_CONTINUE.

Referenced by include_modules_at().

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

Definition at line 388 of file class.c.

References obj, rb_class_boot(), rb_class_tbl, rb_cObject, rb_const_set(), rb_intern, rb_name_class(), and st_add_direct().

Referenced by Init_class_hierarchy().

static VALUE class_alloc | ( | VALUE | flags,
|  | VALUE | klass
| ) |  |
| static

Allocates a struct RClass for a new class.

Parameters

  flags | initial value for basic.flags of the returned class.
  klass | the 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 50 of file class.c.

References ALLOC, NEWOBJ_OF, obj, Qnil, RCLASS_CONST_TBL, RCLASS_EXT, RCLASS_IV_INDEX_TBL, RCLASS_IV_TBL, RCLASS_M_TBL, RCLASS_ORIGIN, RCLASS_REFINED_CLASS, and RCLASS_SUPER.

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

static void class_init_copy_check | ( | VALUE | clone,
|  | VALUE | orig
| ) |  |
| static

Definition at line 181 of file class.c.

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

Referenced by rb_mod_init_copy().

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

Definition at line 1009 of file class.c.

References ary, BUILTIN_TYPE, FL_SINGLETON, FL_TEST, func, list, method_entry_i(), mod, r, rb_ary_new(), rb_scan_args(), RCLASS_M_TBL, RCLASS_ORIGIN, RCLASS_SUPER, recur, RTEST, st_foreach(), st_free_table(), st_init_numtable(), T_ICLASS, and TRUE.

Referenced by rb_class_instance_methods(), rb_class_private_instance_methods(), rb_class_protected_instance_methods(), rb_class_public_instance_methods(), rb_obj_methods(), rb_obj_private_methods(), rb_obj_protected_methods(), and rb_obj_public_methods().

static int clone_const | ( | ID | key,
|  | const rb_const_entry_t * | ce,
|  | st_table * | tbl
| ) |  |
| static

Definition at line 166 of file class.c.

References ALLOC, ST_CONTINUE, and st_insert().

Referenced by clone_const_i().

static int clone_const_i | ( | st_data_t | key,
|  | st_data_t | value,
|  | st_data_t | data
| ) |  |
| static

Definition at line 175 of file class.c.

References clone_const().

Referenced by rb_mod_init_copy(), and rb_singleton_class_clone_and_attach().

static void clone_method | ( | VALUE | klass,
|  | ID | mid,
|  | const rb_method_entry_t * | me
| ) |  |
| static

Definition at line 142 of file class.c.

References rb_method_definition_struct::body, rb_iseq_struct::cref_stack, rb_method_entry_struct::def, rb_method_entry_struct::flag, GetISeqPtr, rb_method_definition_struct::iseq, rb_method_entry_struct::klass, rb_add_method(), RB_GC_GUARD, rb_iseq_clone(), rb_method_entry_set(), rewrite_cref_stack(), rb_iseq_struct::self, rb_method_definition_struct::type, and VM_METHOD_TYPE_ISEQ.

Referenced by clone_method_i().

static int clone_method_i | ( | st_data_t | key,
|  | st_data_t | value,
|  | st_data_t | data
| ) |  |
| static

Definition at line 159 of file class.c.

References clone_method(), and ST_CONTINUE.

Referenced by rb_mod_init_copy(), and rb_singleton_class_clone_and_attach().

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

Definition at line 724 of file class.c.

References add_refined_method_entry_i(), BUILTIN_TYPE, FALSE, FL_SET, FL_TEST, p, rb_include_class_new(), rb_refinement_module_get_refined_class(), RCLASS_M_TBL, RCLASS_ORIGIN, RCLASS_SUPER, RMODULE_CONST_TBL, RMODULE_INCLUDED_INTO_REFINEMENT, RMODULE_IS_REFINEMENT, RMODULE_M_TBL, st_foreach(), T_CLASS, T_ICLASS, and TRUE.

Referenced by rb_include_module(), and rb_prepend_module().

void Init_class_hierarchy | ( | void |  | ) |

Definition at line 401 of file class.c.

References boot_defclass(), id_attached, rb_cBasicObject, rb_cClass, rb_cModule, rb_cObject, rb_const_set(), rb_intern, and RBASIC.

Referenced by Init_Object().

void Init_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.

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

Definition at line 2987 of file object.c.

References CLASS_OF, conv_method_names, false_and(), false_or(), false_to_s(), false_xor(), i, conv_method_tbl::id, id_const_missing, id_eq, id_eql, id_init_clone, id_init_copy, id_init_dup, id_inspect, id_match, Init_class_hierarchy(), conv_method_tbl::method, method, 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_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_intern, 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_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_lt(), rb_mod_name(), rb_mod_private_constant(), rb_mod_public_constant(), rb_mod_remove_const(), rb_mod_remove_cvar(), rb_mod_to_s(), rb_module_s_alloc(), rb_obj_alloc(), rb_obj_class(), rb_obj_clone(), 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_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().

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

Definition at line 962 of file class.c.

References ins_methods_push().

Referenced by rb_class_instance_methods(), rb_obj_methods(), and rb_obj_singleton_methods().

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

Definition at line 974 of file class.c.

References ins_methods_push(), and NOEX_PRIVATE.

Referenced by rb_class_private_instance_methods(), and rb_obj_private_methods().

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

Definition at line 968 of file class.c.

References ins_methods_push(), and NOEX_PROTECTED.

Referenced by rb_class_protected_instance_methods(), and rb_obj_protected_methods().

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

Definition at line 980 of file class.c.

References ins_methods_push(), and NOEX_PUBLIC.

Referenced by rb_class_public_instance_methods(), and rb_obj_public_methods().

static int ins_methods_push | ( | ID | name,
|  | long | type,
|  | VALUE | ary,
|  | long | visi
| ) |  |
| static

Definition at line 941 of file class.c.

References ID2SYM, NOEX_PRIVATE, NOEX_PROTECTED, NOEX_PUBLIC, rb_ary_push(), and ST_CONTINUE.

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

static VALUE make_metaclass | ( | VALUE | klass | ) |
| inline static

Creates a metaclass of klass.

Parameters

  klass | a 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 340 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_SUPER, T_ICLASS, and tmp.

Referenced by rb_make_metaclass().

static VALUE make_singleton_class | ( | VALUE | obj | ) |
| inline static

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 373 of file class.c.

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

Referenced by rb_make_metaclass().

static int method_entry_i | ( | st_data_t | key,
|  | st_data_t | value,
|  | st_data_t | data
| ) |  |
| static

Definition at line 986 of file class.c.

References rb_method_entry_struct::def, rb_method_entry_struct::flag, list, NULL, Qnil, rb_resolve_refined_method(), st_add_direct(), ST_CONTINUE, st_lookup(), rb_method_definition_struct::type, type, UNDEFINED_METHOD_ENTRY_P, VISI, and VM_METHOD_TYPE_REFINED.

Referenced by class_instance_method_list(), and rb_obj_singleton_methods().

static int move_refined_method | ( | st_data_t | key,
|  | st_data_t | value,
|  | st_data_t | data
| ) |  |
| static

Definition at line 774 of file class.c.

References ALLOC, rb_method_definition_struct::body, rb_method_entry_struct::def, NULL, rb_method_definition_struct::orig_me, st_add_direct(), ST_CONTINUE, ST_DELETE, tbl, rb_method_definition_struct::type, VM_METHOD_TYPE_REFINED, and xfree.

Referenced by rb_prepend_module().

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 95 of file class.c.

References FL_SINGLETON, flags, rb_cClass, rb_eTypeError, rb_obj_classname(), rb_raise(), RB_TYPE_P, RBASIC, and T_CLASS.

Referenced by rb_class_initialize(), and rb_class_new().

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 76 of file class.c.

References class_alloc(), klass, OBJ_INFECT, rb_cClass, RCLASS_M_TBL, RCLASS_SUPER, st_init_numtable(), and T_CLASS.

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

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 473 of file class.c.

References CONST_ID, rb_cObject, and rb_funcall().

Referenced by make_struct(), rb_class_initialize(), rb_define_class(), rb_define_class_id_under(), and rb_struct_define_without_accessor().

VALUE rb_class_instance_methods | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | mod
| ) |  |

Definition at line 1071 of file class.c.

References class_instance_method_list(), and ins_methods_i().

Referenced by Init_Object().

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 117 of file class.c.

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

Referenced by Init_IO(), Init_VM(), make_struct(), rb_define_class_id(), and rb_struct_define_without_accessor().

VALUE rb_class_private_instance_methods | ( | int | argc,
|  | VALUE * | argv,
|  | VALUE | mod
| ) |  |

Definition at line 1109 of file class.c.

References class_instance_method_list(), and ins_methods_priv_i().

Referenced by Init_Object().

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

Definition at line 1086 of file class.c.

References class_instance_method_list(), and ins_methods_prot_i().

Referenced by Init_Object().

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

Definition at line 1124 of file class.c.

References class_instance_method_list(), and ins_methods_pub_i().

Referenced by Init_Object().

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. 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`.
  NameError | 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 499 of file class.c.

References id, klass, rb_class_inherited(), rb_class_real(), rb_cObject, rb_const_defined(), rb_const_get(), rb_const_set(), rb_define_class_id(), rb_eTypeError, rb_intern, rb_name_class(), rb_raise(), RB_TYPE_P, rb_warn(), RCLASS_SUPER, st_add_direct(), and T_CLASS.

Referenced by Init_Array(), Init_bigdecimal(), Init_Bignum(), 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_Object(), Init_pathname(), Init_Proc(), Init_Random(), Init_Rational(), Init_Regexp(), Init_sdbm(), Init_socket(), Init_String(), Init_stringio(), Init_strscan(), Init_Struct(), Init_tcltklib(), Init_Thread(), Init_Time(), Init_tkutil(), Init_VM(), Init_vm_trace(), Init_win32ole(), InitVM_Enumerator(), rb_struct_define_without_accessor(), 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(), and ruby_Init_Continuation_body().

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 452 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().

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`.
  NameError | 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 568 of file class.c.

References klass, rb_class2name(), rb_class_inherited(), rb_class_real(), rb_const_defined_at(), rb_const_get_at(), rb_const_set(), rb_define_class_id(), rb_eTypeError, rb_gc_register_mark_object(), rb_id2name(), rb_id2str(), rb_name_error(), rb_raise(), rb_set_class_path_string(), RB_TYPE_P, rb_warn(), RCLASS_SUPER, and T_CLASS.

Referenced by make_struct(), and 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`.
  NameError | 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 545 of file class.c.

References rb_define_class_id_under(), and rb_intern.

Referenced by Init_Complex(), Init_cparse(), Init_curses(), Init_digest(), Init_dl(), Init_dlcfunc(), Init_dlhandle(), Init_dlptr(), Init_Exception(), Init_fiddle(), Init_fiddle_closure(), Init_fiddle_function(), Init_fiddle_handle(), Init_fiddle_pointer(), Init_File(), Init_GC(), Init_generator(), Init_ISeq(), Init_Math(), 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_hmac(), Init_ossl_ns_spki(), 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_process(), 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_tkutil(), Init_transcode(), Init_VM(), Init_vm_backtrace(), Init_zlib(), InitVM_Enumerator(), rsock_init_ancdata(), rsock_init_sockopt(), and set_syserr().

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

Definition at line 617 of file class.c.

References id, rb_cObject, rb_const_defined(), rb_const_get(), rb_const_set(), rb_define_module_id(), rb_eTypeError, rb_intern, rb_obj_classname(), rb_raise(), RB_TYPE_P, st_add_direct(), and T_MODULE.

Referenced by Init_bigdecimal(), Init_Comparable(), Init_coverage(), Init_cparse(), Init_curses(), Init_digest(), Init_dl(), Init_Enumerable(), Init_etc(), Init_Exception(), Init_fcntl(), Init_fiddle(), Init_fiddle_closure(), Init_File(), Init_GC(), Init_generator(), Init_marshal(), Init_Math(), Init_md5(), Init_nkf(), Init_Object(), Init_openssl(), Init_ossl_asn1(), Init_ossl_bn(), Init_ossl_cipher(), Init_ossl_dh(), Init_ossl_digest(), Init_ossl_dsa(), Init_ossl_hmac(), Init_ossl_ns_spki(), Init_ossl_pkcs5(), Init_ossl_pkey(), Init_ossl_rand(), Init_ossl_rsa(), Init_ossl_ssl(), Init_ossl_ssl_session(), Init_ossl_x509cert(), Init_ossl_x509store(), Init_parser(), Init_process(), Init_psych(), Init_psych_emitter(), Init_psych_parser(), Init_psych_to_ruby(), Init_psych_yaml_tree(), Init_pty(), Init_readline(), Init_rmd160(), Init_sha1(), Init_signal(), Init_syslog(), Init_tcltklib(), Init_tkutil(), Init_zlib(), and process_options().

VALUE rb_define_module_id | ( | ID | id | ) |

Definition at line 606 of file class.c.

References rb_module_new(), and rb_name_class().

Referenced by rb_define_module(), and rb_define_module_id_under().

VALUE rb_define_module_id_under | ( | VALUE | outer,
|  | ID | id
| ) |  |

Definition at line 643 of file class.c.

References rb_class2name(), 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_classname(), rb_raise(), rb_set_class_path_string(), RB_TYPE_P, and T_MODULE.

Referenced by rb_define_module_under().

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

Definition at line 637 of file class.c.

References rb_define_module_id_under(), and rb_intern.

Referenced by init_constants(), Init_curses(), Init_digest(), Init_File(), Init_GC(), Init_generator(), Init_IO(), Init_ossl_asn1(), Init_ossl_dh(), Init_ossl_dsa(), Init_ossl_ns_spki(), Init_ossl_pkcs5(), Init_ossl_pkey(), Init_ossl_rand(), Init_ossl_rsa(), Init_ossl_ssl(), Init_ossl_ssl_session(), Init_ossl_x509(), Init_ossl_x509cert(), Init_ossl_x509store(), Init_parser(), Init_process(), Init_psych_to_ruby(), Init_psych_yaml_tree(), Init_stringio(), Init_syslog(), Init_tcltklib(), Init_win32ole(), and InitVM_console().

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

Definition at line 663 of file class.c.

References BUILTIN_TYPE, class_alloc(), klass, OBJ_INFECT, rb_cClass, RB_TYPE_P, RBASIC, RCLASS_CONST_TBL, RCLASS_IV_TBL, RCLASS_M_TBL, RCLASS_ORIGIN, RCLASS_SUPER, st_init_numtable(), and T_ICLASS.

Referenced by add_activated_refinement(), include_modules_at(), and rb_using_refinement().

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

Definition at line 695 of file class.c.

References Check_Type, include_modules_at(), OBJ_INFECT, OBJ_UNTRUSTED, rb_clear_cache(), rb_eArgError, rb_frozen_class_p(), rb_raise(), rb_secure(), RB_TYPE_P, RCLASS_ORIGIN, and T_MODULE.

Referenced by Init_Array(), Init_date_core(), Init_dbm(), Init_digest(), Init_Dir(), Init_File(), Init_gdbm(), Init_Hash(), Init_IO(), Init_Numeric(), Init_Object(), Init_ossl_asn1(), Init_ossl_x509name(), Init_Range(), Init_sdbm(), Init_String(), Init_stringio(), Init_Struct(), Init_syslog(), Init_Time(), Init_zlib(), InitVM_Enumerator(), rb_extend_object(), and rb_mod_append_features().

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

  obj | An object.
  unused | ignored.

Returns
  The singleton class of the object.

Definition at line 430 of file class.c.

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

Referenced by make_struct(), rb_class_initialize(), rb_define_class_id(), rb_struct_define_without_accessor(), and singleton_class_of().

VALUE rb_mod_ancestors | ( | VALUE | mod | ) |

Definition at line 920 of file class.c.

References ary, BUILTIN_TYPE, FL_SINGLETON, FL_TEST, klass, p, rb_ary_new(), rb_ary_push(), RBASIC, RCLASS_ORIGIN, RCLASS_SUPER, and T_ICLASS.

Referenced by Init_Object(), and rb_threadptr_pending_interrupt_check_mask().

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

Definition at line 890 of file class.c.

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

Referenced by Init_Object().

VALUE rb_mod_included_modules | ( | VALUE | mod | ) |

Definition at line 854 of file class.c.

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

Referenced by Init_Object().

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

Definition at line 196 of file class.c.

References class_init_copy_check(), CLASS_OF, clone_const_i(), clone_method_i(), CONST_ID, FL_SINGLETON, FL_TEST, id, klass, rb_free_const_table(), rb_free_m_table(), rb_obj_init_copy(), rb_singleton_class_attached(), rb_singleton_class_clone(), RB_TYPE_P, RBASIC, RCLASS_CONST_TBL, RCLASS_EXT, RCLASS_IV_TBL, RCLASS_M_TBL, RCLASS_SUPER, st_copy(), st_delete(), st_foreach(), st_free_table(), st_init_numtable(), and T_CLASS.

Referenced by Init_Object().

VALUE rb_module_new | ( | void |  | ) |

Definition at line 596 of file class.c.

References class_alloc(), rb_cModule, RCLASS_M_TBL, st_init_numtable(), and T_MODULE.

Referenced by rb_define_module_id(), rb_eval_string_wrap(), rb_load_internal(), rb_mod_refine(), and rb_module_s_alloc().

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

Definition at line 1151 of file class.c.

References class_instance_method_list(), CLASS_OF, ins_methods_i(), rb_obj_singleton_methods(), rb_scan_args(), recur, retry, and RTEST.

Referenced by Init_Object().

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

Definition at line 1194 of file class.c.

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

Referenced by Init_Object().

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

Definition at line 1179 of file class.c.

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

Referenced by Init_Object().

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

Definition at line 1209 of file class.c.

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

Referenced by Init_Object().

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

Definition at line 1248 of file class.c.

References ary, CLASS_OF, FL_SINGLETON, FL_TEST, ins_methods_i(), klass, list, method_entry_i(), Qtrue, rb_ary_new(), rb_scan_args(), RB_TYPE_P, RCLASS_M_TBL, RCLASS_SUPER, recur, RTEST, st_foreach(), st_free_table(), st_init_numtable(), and T_ICLASS.

Referenced by Init_Object(), and rb_obj_methods().

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

Definition at line 801 of file class.c.

References Check_Type, class_alloc(), include_modules_at(), move_refined_method(), OBJ_INFECT, OBJ_UNTRUSTED, rb_clear_cache(), rb_eArgError, rb_frozen_class_p(), rb_raise(), rb_secure(), rb_vm_check_redefinition_by_prepend(), RCLASS_M_TBL, RCLASS_ORIGIN, RCLASS_SUPER, st_foreach(), st_init_numtable(), T_ICLASS, and T_MODULE.

Referenced by rb_mod_prepend_features().

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 Fixnum 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 1470 of file class.c.

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

Referenced by Init_date_core(), Init_eval(), Init_eval_method(), Init_nkf(), Init_Proc(), Init_process(), Init_Time(), Init_top_self(), Init_VM(), num_sadded(), rb_extend_object(), rb_mod_modfunc(), rb_mod_private_method(), rb_mod_public_method(), rb_obj_define_method(), rb_obj_instance_eval(), rb_obj_instance_exec(), rb_obj_singleton_class(), and vm_define_method().

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 289 of file class.c.

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

Referenced by make_metaclass(), make_singleton_class(), rb_mod_init_copy(), rb_obj_clone(), and rb_singleton_class_clone_and_attach().

VALUE rb_singleton_class_clone | ( | VALUE | obj | ) |

Definition at line 241 of file class.c.

References Qundef, and rb_singleton_class_clone_and_attach().

Referenced by rb_mod_init_copy(), and rb_singleton_class_clone_and_attach().

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

Definition at line 247 of file class.c.

References BUILTIN_TYPE, class_alloc(), clone_const_i(), clone_method_i(), FL_SET, FL_SINGLETON, FL_TEST, flags, klass, Qundef, rb_singleton_class_attached(), rb_singleton_class_clone(), RBASIC, RCLASS_CONST_TBL, RCLASS_EXT, RCLASS_IV_TBL, RCLASS_M_TBL, RCLASS_SUPER, st_copy(), st_foreach(), st_init_numtable(), and T_CLASS.

Referenced by rb_obj_clone(), and rb_singleton_class_clone().

VALUE rb_special_singleton_class | ( | VALUE | obj | ) |

Definition at line 1391 of file class.c.

References special_singleton_class_of().

Referenced by rb_obj_instance_eval(), and rb_obj_instance_exec().

static NODE* rewrite_cref_stack | ( | NODE * | node,
|  | VALUE | old_klass,
|  | VALUE | new_klass
| ) |  |
| static

Definition at line 125 of file class.c.

References NEW_CREF, and NULL.

Referenced by clone_method().

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 1406 of file class.c.

References BUILTIN_TYPE, FIXNUM_P, FL_SINGLETON, FL_TAINT, FL_TEST, FL_UNSET, FL_UNTRUSTED, FLONUM_P, id_attached, klass, NIL_P(), OBJ_FREEZE, OBJ_FROZEN, OBJ_TAINT, OBJ_TAINTED, OBJ_UNTRUST, OBJ_UNTRUSTED, rb_bug(), rb_eTypeError, rb_ivar_get(), rb_make_metaclass(), rb_raise(), RBASIC, SPECIAL_CONST_P, special_singleton_class_of(), SYMBOL_P, T_BIGNUM, T_FLOAT, and type.

Referenced by rb_define_singleton_method(), and rb_singleton_class().

static VALUE special_singleton_class_of | ( | VALUE | obj | ) |
| inline static

Definition at line 1382 of file class.c.

References Qfalse, Qnil, Qtrue, rb_cFalseClass, rb_cNilClass, rb_cTrueClass, and SPECIAL_SINGLETON.

Referenced by rb_special_singleton_class(), and singleton_class_of().

## Variable Documentation

ID id_attached
| static

Definition at line 35 of file class.c.

Referenced by Init_class_hierarchy(), rb_singleton_class_attached(), and singleton_class_of().

st_table* rb_class_tbl

Definition at line 23 of file variable.c.

Referenced by boot_defclass().