method
local_variables
v1_9_2_180 -
Show latest stable
- Class:
Kernel
local_variables()public
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(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 (cfp->lfp != cfp->dfp) {
/* block */
VALUE *dfp = GC_GUARDED_PTR_REF(cfp->dfp[0]);
if (vm_collect_local_variables_in_heap(th, dfp, ary)) {
break;
}
else {
while (cfp->dfp != dfp) {
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
}
}
}
else {
break;
}
}
return ary;
} Related methods
- Instance methods
- Array
- BigDecimal
- Complex
- Float
- Integer
- Rational
- String
- __callee__
- __method__
- `
- abort
- at_exit
- autoload
- autoload?
- binding
- block_given?
- callcc
- caller
- catch
- chomp
- chop
- eval
- exec
- exit
- exit!
- fail
- fork
- format
- gets
- global_variables
- gsub
- iterator?
- lambda
- load
- local_variables
- loop
- p
- pretty_inspect
- printf
- proc
- putc
- puts
- raise
- rand
- readline
- readlines
- require
- require_relative
- select
- set_trace_func
- sleep
- spawn
- sprintf
- srand
- sub
- syscall
- system
- test
- throw
- trace_var
- trap
- untrace_var
- warn
- Class methods
- URI
- open
- pp
- Private methods
-
open_uri_original_open -
JSON -
Pathname -
URI -
j -
jj -
open -
open_uri_original_open -
pp -
scanf