local_variables()
public
Returns the names of the current local variables.
fred = 1
for i in 1..10
end
local_variables
Show source
static VALUE
rb_f_local_variables(void)
{
VALUE ary = rb_ary_new();
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp =
vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp));
int i;
while (cfp) {
if (cfp->iseq) {
for (i = 0; i < cfp->iseq->local_table_size; i++) {
ID lid = cfp->iseq->local_table[i];
if (lid) {
const char *vname = rb_id2name(lid);
/* should skip temporary variable */
if (vname) {
rb_ary_push(ary, ID2SYM(lid));
}
}
}
}
if (!VM_EP_LEP_P(cfp->ep)) {
/* block */
VALUE *ep = VM_CF_PREV_EP(cfp);
if (vm_collect_local_variables_in_heap(th, ep, ary)) {
break;
}
else {
while (cfp->ep != ep) {
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
}
}
}
else {
break;
}
}
return ary;
}