Ruby????????????
???????????? ???????[ 2014/3/20 11:04:23 ] ????????Ruby ??? ????
????????????? while ????? module ??????????ancestors?????????????????? module?????? for ??????? module ???????????? klass ?????????У??????????????????????????? module ???? c ?? c ????????
????????? module ??????????????????????У????? superclass_seen ?????ж????????????????????????????????????????????????????嵽???????????????????????
?????????????????? 31 ?д?????????????? rb_include_class_new ???????鴴?????????????include class???????? c ????????????????????????????????? c ??????????????? rb_include_class_new ????????δ???????????
VALUE
rb_include_class_new(VALUE module?? VALUE super)
{
VALUE klass = class_alloc(T_ICLASS?? rb_cClass);
if (BUILTIN_TYPE(module) == T_ICLASS) {
module = RBASIC(module)->klass;
}
if (!RCLASS_IV_TBL(module)) {
RCLASS_IV_TBL(module) = st_init_numtable();
}
if (!RCLASS_CONST_TBL(module)) {
RCLASS_CONST_TBL(module) = st_init_numtable();
}
RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module);
RCLASS_M_TBL(klass) = RCLASS_M_TBL(RCLASS_ORIGIN(module));
RCLASS_SUPER(klass) = super;
if (RB_TYPE_P(module?? T_ICLASS)) {
RBASIC(klass)->klass = RBASIC(module)->klass;
}
else {
RBASIC(klass)->klass = module;
}
OBJ_INFECT(klass?? module);
OBJ_INFECT(klass?? super);
return (VALUE)klass;
}
?????? 4 ?У?class_alloc ???????????????????????? T_ICLASS ?????????????????Ruby ???????????????????????????е??????????????????????????ж??????????????? klass ?????飬????????????????????
?????? 17 ???и? RCLASS_ORIGIN ??????????????????????????Ruby ????У??ú????????£?
????#define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin)
???????????????????????? origin ?????????????????????????????????????????????е???????????????????????????????Ruby ?????????????????????
?????????Щ???????????????????????????????????????????????δ?????????????????????????????????
????A = Module.new
????B = Module.new
????module C
????include A?? B # Inclusion is done by this line
????end
????????????? C ?? include ????????????? Module#include ???????????????????? append_features ?? included ???????????????????? Module#append_features ?????????
???????????????????飬Ruby ???????????????????????????飬???????????????????????????????????????????????鴴?????????????????? C ?????????С?
????????????????????????Щ????????????????顢????????????????????????????? Refinement ????????????????????????????????????
????????????????????????????????????????????????????????У???????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11