local_variable_get(p1)
public
Returns the value of the local variable symbol.
def foo
a = 1
binding.local_variable_get(:a)
binding.local_variable_get(:b)
end
This method is the short version of the following code:
binding.eval("#{symbol}")
static VALUE
bind_local_variable_get(VALUE bindval, VALUE sym)
{
ID lid = check_local_id(bindval, &sym);
const rb_binding_t *bind;
const VALUE *ptr;
const rb_env_t *env;
if (!lid) goto undefined;
GetBindingPtr(bindval, bind);
env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
if ((ptr = get_local_variable_ptr(&env, lid)) == NULL) {
sym = ID2SYM(lid);
undefined:
rb_name_err_raise("local variable `%1$s' is not defined for %2$s",
bindval, sym);
}
return *ptr;
}