Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Binding#local_variables
() -> ::Array[::Symbol]
binding.local_variables → Array
proc.c
View on GitHub ↗
static VALUE
bind_local_variables(VALUE bindval)
{
const rb_binding_t *bind;
const rb_env_t *env;
GetBindingPtr(bindval, bind);
env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
return rb_vm_env_local_variables(env);
}
Returns the names of the binding’s local variables as symbols.
Example
def foo a = 1 2.times do |n| binding.local_variables #=> [:a, :n] end end
This method is the short version of the following code:
Example
binding.eval("local_variables")
See also
#local_variable_get
#local_variable_set
#local_variable_defined?
#receiver
also in
4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0