Method: Kernel#local_variables
- Defined in:
- vm_eval.c
#local_variables ⇒ Array
Returns the names of the current local variables.
fred = 1
for i in 1..10
# ...
end
local_variables #=> [:fred, :i]
2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 |
# File 'vm_eval.c', line 2687 static VALUE rb_f_local_variables(VALUE _) { struct local_var_list vars; rb_execution_context_t *ec = GET_EC(); rb_control_frame_t *cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp)); unsigned int i; local_var_list_init(&vars); while (cfp) { if (cfp->iseq) { for (i = 0; i < ISEQ_BODY(cfp->iseq)->local_table_size; i++) { local_var_list_add(&vars, ISEQ_BODY(cfp->iseq)->local_table[i]); } } if (!VM_ENV_LOCAL_P(cfp->ep)) { /* block */ const VALUE *ep = VM_CF_PREV_EP(cfp); if (vm_collect_local_variables_in_heap(ep, &vars)) { break; } else { while (cfp->ep != ep) { cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); } } } else { break; } } return local_var_list_finish(&vars); } |