Kernel.local_variables to list UPVAR as well

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-05-14 17:38:27 +09:00
parent 232ec102d6
commit 27df1a84bc
2 changed files with 25 additions and 1 deletions
+19 -1
View File
@@ -137,10 +137,28 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
}
irep = proc->body.irep;
if (!irep->lv) {
return mrb_ary_new(mrb);
}
ret = mrb_ary_new_capa(mrb, irep->nlocals - 1);
for (i = 0; i < (irep->nlocals - 1); ++i) {
for (i = 0; i + 1 < irep->nlocals; ++i) {
mrb_ary_push(mrb, ret, mrb_symbol_value(irep->lv[i].name));
}
if (proc->env) {
struct REnv *e = proc->env;
while (e) {
if (!MRB_PROC_CFUNC_P(mrb->c->cibase[e->cioff].proc)) {
irep = mrb->c->cibase[e->cioff].proc->body.irep;
if (irep->lv) {
for (i = 0; i + 1 < irep->nlocals; ++i) {
mrb_ary_push(mrb, ret, mrb_symbol_value(irep->lv[i].name));
}
}
}
e = (struct REnv*)e->c;
}
}
return ret;
}
+6
View File
@@ -81,4 +81,10 @@ assert('Kernel.local_variables') do
vars = Kernel.local_variables.sort
assert_equal [:a, :b, :vars], vars
proc {
c = 2
vars = Kernel.local_variables.sort
assert_equal [:a, :b, :c, :vars], vars
}.call
end