static VALUE rb_ary_flatten(int argc, VALUE *argv, VALUE ary) { int mod = 0, level = -1; VALUE result, lv;
rb_scan_args(argc, argv, "01", &lv); if (!NIL_P(lv)) level = NUM2INT(lv); if (level == 0) return ary_make_shared_copy(ary);
result = flatten(ary, level, &mod); OBJ_INFECT(result, ary);
return result; }
这段是从ruby-doc上贴的源码,感觉像是截出来的一部分,不是完整的。array.flatten 方法对于很深的嵌套好像都有效,这段源码好像没用到嵌套。