33 #define id_attached id__attached__ 40 if (super && super !=
Qundef) {
57 rb_module_add_to_subclasses_list(
VALUE module,
VALUE iclass)
62 entry->
klass = iclass;
127 class_detach_subclasses(
VALUE klass,
VALUE arg)
139 class_detach_module_subclasses(
VALUE klass,
VALUE arg)
186 RCLASS_M_TBL_INIT(
VALUE c)
205 RCLASS_SET_SUPER(klass, super);
206 RCLASS_M_TBL_INIT(klass);
268 clone_method_i(
ID key,
VALUE value,
void *data)
293 clone_const_i(
ID key,
VALUE value,
void *data)
299 class_init_copy_check(
VALUE clone,
VALUE orig)
317 class_init_copy_check(clone, orig);
357 RCLASS_M_TBL_INIT(clone);
379 VALUE clone = class_alloc(
RBASIC(klass)->flags, 0);
402 RCLASS_M_TBL_INIT(clone);
433 #define METACLASS_OF(k) RBASIC(k)->klass 434 #define SET_METACLASS_OF(k, cls) RBASIC_SET_CLASS(k, cls) 441 #define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k)) 444 rb_singleton_class_has_metaclass_p(
VALUE sklass)
453 !rb_singleton_class_has_metaclass_p(sklass));
461 #define HAVE_METACLASS_P(k) \ 462 (FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \ 463 rb_singleton_class_has_metaclass_p(k)) 472 #define ENSURE_EIGENCLASS(klass) \ 473 (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass)) 486 make_metaclass(
VALUE klass)
520 make_singleton_class(
VALUE obj)
535 boot_defclass(
const char *
name,
VALUE super)
580 return make_metaclass(obj);
583 return make_singleton_class(obj);
625 return rb_funcall(super, inherited, 1, klass);
752 RCLASS_M_TBL_INIT(mdl);
823 module =
RBASIC(module)->klass;
837 RCLASS_SET_SUPER(klass, super);
850 static int include_modules_at(
const VALUE klass,
VALUE c,
VALUE module,
int search_super);
868 ensure_includable(klass, module);
876 add_refined_method_entry_i(
ID key,
VALUE value,
void *data)
883 include_modules_at(
const VALUE klass,
VALUE c,
VALUE module,
int search_super)
886 int method_changed = 0, constant_changed = 0;
890 int superclass_seen =
FALSE;
902 if (!superclass_seen) {
909 if (!search_super)
break;
910 superclass_seen =
TRUE;
914 c = RCLASS_SET_SUPER(c, iclass);
919 rb_module_add_to_subclasses_list(m, iclass);
923 VALUE refined_class =
942 return method_changed;
946 move_refined_method(
ID key,
VALUE value,
void *data)
953 if (me->
def->body.refined.orig_me) {
978 ensure_includable(klass, module);
981 if (origin == klass) {
982 origin = class_alloc(
T_ICLASS, klass);
985 RCLASS_SET_SUPER(klass, origin);
986 RCLASS_SET_ORIGIN(klass, origin);
988 RCLASS_M_TBL_INIT(klass);
991 changed = include_modules_at(klass, klass, module,
FALSE);
1114 ins_methods_push(name, ary);
1124 ins_methods_push(name, ary);
1133 ins_methods_push(name, ary);
1142 ins_methods_push(name, ary);
1153 method_entry_i(
ID key,
VALUE value,
void *data)
1181 int recur, prepended = 0;
1243 return class_instance_method_list(argc, argv, mod, 0, ins_methods_i);
1258 return class_instance_method_list(argc, argv, mod, 0, ins_methods_prot_i);
1281 return class_instance_method_list(argc, argv, mod, 0, ins_methods_priv_i);
1296 return class_instance_method_list(argc, argv, mod, 0, ins_methods_pub_i);
1333 if (argc > 0 && !
RTEST(argv[0])) {
1336 return class_instance_method_list(argc, argv,
CLASS_OF(obj), 1, ins_methods_i);
1351 return class_instance_method_list(argc, argv,
CLASS_OF(obj), 1, ins_methods_prot_i);
1366 return class_instance_method_list(argc, argv,
CLASS_OF(obj), 1, ins_methods_priv_i);
1381 return class_instance_method_list(argc, argv,
CLASS_OF(obj), 1, ins_methods_pub_i);
1539 undef_method_i(
ID name,
VALUE value,
void *data)
1563 #define SPECIAL_SINGLETON(x,c) do {\ 1570 special_singleton_class_of(
VALUE obj)
1581 return special_singleton_class_of(obj);
1594 singleton_class_of(
VALUE obj)
1603 klass = special_singleton_class_of(obj);
1605 rb_bug(
"unknown immediate %p", (
void *)obj);
1618 klass =
RBASIC(obj)->klass;
1665 klass =
RBASIC(obj)->klass;
1691 VALUE klass = singleton_class_of(obj);
1786 const VALUE k = ptr[i];
1789 if (++i >=
len)
break;
1797 NORETURN(
static void rb_keyword_error(
const char *error,
VALUE keys));
1799 rb_keyword_error(
const char *error,
VALUE keys)
1804 NORETURN(
static void unknown_keyword_error(
VALUE hash,
const ID *table,
int keywords));
1806 unknown_keyword_error(
VALUE hash,
const ID *table,
int keywords)
1810 for (i = 0; i < keywords; i++) {
1831 VALUE parthash[2] = {0, 0};
1832 VALUE hash = *orighash;
1839 *orighash = parthash[1];
1854 #define extract_kwarg(keyword, val) \ 1855 (key = (st_data_t)(keyword), values ? \ 1856 st_delete(rb_hash_tbl_raw(keyword_hash), &key, (val)) : \ 1857 st_lookup(rb_hash_tbl_raw(keyword_hash), key, (val))) 1859 if (
NIL_P(keyword_hash)) keyword_hash = 0;
1863 optional = -1-optional;
1866 for (j = 0; j < required + optional; j++) {
1871 for (; i < required; i++) {
1876 if (values) values[i] = (
VALUE)val;
1883 if (!
NIL_P(missing)) {
1884 rb_keyword_error(
"missing", missing);
1888 if (optional && keyword_hash) {
1889 for (i = 0; i < optional; i++) {
1892 if (values) values[required+i] = (
VALUE)val;
1897 if (!rest && keyword_hash) {
1898 if (
RHASH_SIZE(keyword_hash) > (
unsigned int)(values ? 0 : j)) {
1899 unknown_keyword_error(keyword_hash, table, required+optional);
1903 #undef extract_kwarg 1911 const char *p = fmt;
1914 int f_var = 0, f_hash = 0, f_block = 0;
1915 int n_lead = 0, n_opt = 0, n_trail = 0, n_mand;
1916 int argi = 0, last_idx = -1;
1944 rb_fatal(
"bad scan arg format: %s", fmt);
1946 n_mand = n_lead + n_trail;
1951 va_start(vargs, fmt);
1954 if (f_hash && n_mand < argc) {
1961 if (!f_var && n_mand + n_opt < argc)
1968 if (!(last_hash = hash)) argc--;
1969 else last_idx = argc - 1;
1970 hash = opts ? opts :
Qnil;
1975 for (i = n_lead; i-- > 0; ) {
1976 var = va_arg(vargs,
VALUE *);
1977 if (var) *var = (argi == last_idx) ? last_hash : argv[argi];
1981 for (i = n_opt; i-- > 0; ) {
1982 var = va_arg(vargs,
VALUE *);
1983 if (argi < argc - n_trail) {
1984 if (var) *var = (argi == last_idx) ? last_hash : argv[argi];
1988 if (var) *var =
Qnil;
1993 int n_var = argc - argi - n_trail;
1995 var = va_arg(vargs,
VALUE *);
1998 int f_last = (last_idx + 1 == argc - n_trail);
2009 for (i = n_trail; i-- > 0; ) {
2010 var = va_arg(vargs,
VALUE *);
2011 if (var) *var = (argi == last_idx) ? last_hash : argv[argi];
2016 var = va_arg(vargs,
VALUE *);
2017 if (var) *var = hash;
2021 var = va_arg(vargs,
VALUE *);
void rb_fatal(const char *fmt,...)
void rb_class_remove_from_super_subclasses(VALUE klass)
#define UNDEFINED_METHOD_ENTRY_P(me)
void rb_class_detach_subclasses(VALUE klass)
VALUE rb_define_module_id_under(VALUE outer, ID id)
void rb_bug(const char *fmt,...)
RUBY_EXTERN VALUE rb_cFalseClass
VALUE rb_class_public_instance_methods(int argc, const VALUE *argv, VALUE mod)
VALUE rb_mod_include_p(VALUE mod, VALUE mod2)
rb_method_entry_t * rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex)
#define RB_FL_SET_RAW(x, f)
void rb_check_inheritable(VALUE super)
Ensures a class can be derived from super.
#define RCLASS_CONST_TBL(c)
const rb_method_entry_t * rb_method_entry_clone(const rb_method_entry_t *me)
void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi)
#define RB_OBJ_WRITTEN(a, oldv, b)
rb_subclass_entry_t * next
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super)
Defines a class under the namespace of outer.
void rb_class_remove_from_module_subclasses(VALUE klass)
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
VALUE rb_class_protected_instance_methods(int argc, const VALUE *argv, VALUE mod)
#define OBJ_INIT_COPY(obj, orig)
VALUE rb_mod_ancestors(VALUE mod)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_singleton_class_clone(VALUE obj)
struct st_table * rb_hash_tbl_raw(VALUE hash)
VALUE rb_mod_init_copy(VALUE clone, VALUE orig)
VALUE rb_ary_tmp_new(long capa)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
void rb_freeze_singleton_class(VALUE x)
void Init_class_hierarchy(void)
#define RBASIC_SET_CLASS(obj, cls)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_ivar_get(VALUE, ID)
#define SET_METACLASS_OF(k, cls)
VALUE rb_exc_new_str(VALUE etype, VALUE str)
void rb_vm_check_redefinition_by_prepend(VALUE klass)
void rb_clear_constant_cache(void)
int rb_const_defined(VALUE, ID)
void rb_include_module(VALUE klass, VALUE module)
#define FL_TEST_RAW(x, f)
VALUE rb_refinement_module_get_refined_class(VALUE module)
void rb_define_protected_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
void rb_vm_rewrite_cref(rb_cref_t *node, VALUE old_klass, VALUE new_klass, rb_cref_t **new_cref_ptr)
void rb_undef_method(VALUE klass, const char *name)
VALUE rb_hash_keys(VALUE hash)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
#define NEWOBJ_OF(obj, type, klass, flags)
void rb_prepend_module(VALUE klass, VALUE module)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
VALUE rb_extract_keywords(VALUE *orighash)
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
#define RB_TYPE_P(obj, type)
VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
VALUE rb_class_name(VALUE)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
void rb_method_entry_copy(rb_method_entry_t *dst, const rb_method_entry_t *src)
RUBY_EXTERN VALUE rb_cObject
VALUE rb_special_singleton_class(VALUE obj)
#define RGENGC_WB_PROTECTED_CLASS
void rb_attr(VALUE, ID, int, int, int)
RUBY_EXTERN VALUE rb_cBasicObject
#define RMODULE_CONST_TBL(m)
#define OBJ_WB_UNPROTECT(x)
int rb_class_has_methods(VALUE c)
VALUE rb_obj_public_methods(int argc, const VALUE *argv, VALUE obj)
RUBY_EXTERN VALUE rb_mKernel
void rb_frozen_class_p(VALUE klass)
Asserts that klass is not a frozen class.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
RUBY_EXTERN VALUE rb_cTrueClass
struct rb_method_definition_struct *const def
struct rb_id_table * rb_id_table_create(size_t capa)
void rb_class_subclass_add(VALUE super, VALUE klass)
VALUE rb_define_module_id(ID id)
#define META_CLASS_OF_CLASS_CLASS_P(k)
whether k is a meta^(n)-class of Class class
const rb_method_entry_t * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me)
RUBY_EXTERN VALUE rb_cModule
void rb_gc_register_mark_object(VALUE obj)
#define MEMCPY(p1, p2, type, n)
#define OBJ_FREEZE_RAW(x)
#define RCLASS_REFINED_CLASS(c)
VALUE rb_const_get(VALUE, ID)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc, rb_method_visibility_t visi)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
#define RARRAY_CONST_PTR(a)
int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val)
void rb_class_foreach_subclass(VALUE klass, void(*f)(VALUE, VALUE), VALUE arg)
VALUE rb_sprintf(const char *format,...)
unsigned long rb_serial_t
VALUE rb_include_class_new(VALUE module, VALUE super)
VALUE rb_class_path(VALUE)
size_t rb_id_table_size(const struct rb_id_table *tbl)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_check_hash_type(VALUE hash)
VALUE rb_class_instance_methods(int argc, const VALUE *argv, VALUE mod)
void rb_clear_method_cache_by_class(VALUE)
void rb_const_set(VALUE, ID, VALUE)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
#define extract_kwarg(keyword, val)
#define METHOD_ENTRY_VISI(me)
void rb_undef_methods_from(VALUE klass, VALUE super)
void rb_name_class(VALUE, ID)
VALUE rb_make_metaclass(VALUE obj, VALUE unused)
VALUE rb_obj_protected_methods(int argc, const VALUE *argv, VALUE obj)
void rb_alias(VALUE, ID, ID)
RUBY_EXTERN VALUE rb_cClass
void rb_class_detach_module_subclasses(VALUE klass)
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
#define RB_OBJ_WRITE(a, slot, b)
int rb_const_defined_at(VALUE, ID)
NORETURN(static void rb_keyword_error(const char *error, VALUE keys))
void rb_free_const_table(struct rb_id_table *tbl)
void rb_define_method_id(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
void rb_singleton_class_attached(VALUE klass, VALUE obj)
Attach a object to a singleton class.
#define UNLIMITED_ARGUMENTS
VALUE rb_module_new(void)
#define ENSURE_EIGENCLASS(klass)
ensures klass belongs to its own eigenclass.
VALUE rb_block_proc(void)
void rb_define_attr(VALUE klass, const char *name, int read, int write)
Defines (a) public accessor method(s) for an attribute.
#define RBASIC_CLASS(obj)
int rb_class_ivar_set(VALUE klass, ID vid, VALUE value)
void rb_error_arity(int argc, int min, int max)
#define RB_OBJ_FROZEN_RAW(x)
VALUE rb_singleton_class_get(VALUE obj)
Returns the singleton class of obj, or nil if obj is not a singleton object.
VALUE rb_obj_singleton_methods(int argc, const VALUE *argv, VALUE obj)
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi)
st_table * rb_st_copy(VALUE obj, struct st_table *orig_tbl)
VALUE rb_str_cat_cstr(VALUE, const char *)
int rb_singleton_class_internal_p(VALUE sklass)
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
VALUE rb_class_private_instance_methods(int argc, const VALUE *argv, VALUE mod)
VALUE rb_obj_methods(int argc, const VALUE *argv, VALUE obj)
VALUE rb_const_get_at(VALUE, ID)
VALUE rb_mod_included_modules(VALUE mod)
VALUE rb_define_class_id(ID id, VALUE super)
Defines a new class.
rb_serial_t rb_next_class_serial(void)
#define SPECIAL_SINGLETON(x, c)
#define CONST_ID(var, str)
rb_id_table_iterator_result
#define rb_intern_const(str)
#define SPECIAL_CONST_P(x)
VALUE rb_define_module(const char *name)
void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data)
int rb_vm_add_root_module(ID id, VALUE module)
VALUE rb_obj_private_methods(int argc, const VALUE *argv, VALUE obj)
VALUE rb_class_real(VALUE cl)
Looks up the nearest ancestor of cl, skipping singleton classes or module inclusions.
VALUE rb_class_new(VALUE super)
Creates a new class.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
VALUE rb_class_boot(VALUE super)
A utility function that wraps class_alloc.
RUBY_EXTERN VALUE rb_cNilClass
void rb_set_class_path_string(VALUE, VALUE, VALUE)
VALUE rb_attr_get(VALUE, ID)
VALUE rb_keyword_error_new(const char *error, VALUE keys)
VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)