Add optional argument to Module#class_variables.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2019-09-19 14:41:59 +09:00
parent 01ce5824f0
commit 683baec4f0
2 changed files with 5 additions and 2 deletions
+4 -1
View File
@@ -595,7 +595,7 @@ cv_i(mrb_state *mrb, mrb_sym sym, mrb_value v, void *p)
/* 15.2.2.4.19 */
/*
* call-seq:
* mod.class_variables -> array
* mod.class_variables(inherit=true) -> array
*
* Returns an array of the names of class variables in <i>mod</i>.
*
@@ -613,11 +613,14 @@ mrb_mod_class_variables(mrb_state *mrb, mrb_value mod)
{
mrb_value ary;
struct RClass *c;
mrb_bool inherit = TRUE;
mrb_get_args(mrb, "|b", &inherit);
ary = mrb_ary_new(mrb);
c = mrb_class_ptr(mod);
while (c) {
iv_foreach(mrb, c->iv, cv_i, &ary);
if (!inherit) break;
c = c->super;
}
return ary;