local_variables()
public
Returns the names of the current local variables.
fred = 1
for i in 1..10
end
local_variables
Show source
/*
* call-seq:
* local_variables => array
*
* Returns the names of the current local variables.
*
* fred = 1
* for i in 1..10
* # ...
* end
* local_variables #=> ["fred", "i"]
*/
static VALUE
rb_f_local_variables()
{
ID *tbl;
int n, i;
VALUE ary = rb_ary_new();
struct RVarmap *vars;
tbl = ruby_scope->local_tbl;
if (tbl) {
n = *tbl++;
for (i=2; i<n; i++) { /* skip first 2 ($_ and $~) */
if (!rb_is_local_id(tbl[i])) continue; /* skip flip states */
rb_ary_push(ary, rb_str_new2(rb_id2name(tbl[i])));
}
}
vars = ruby_dyna_vars;
while (vars) {
if (vars->id && rb_is_local_id(vars->id)) { /* skip $_, $~ and flip states */
rb_ary_push(ary, rb_str_new2(rb_id2name(vars->id)));
}
vars = vars->next;
}
return ary;
}