binding()
public
Returns the binding associated with
prc. Note that Kernel#eval accepts
either a Proc or a Binding object as its second parameter.
def fred(param)
proc {}
end
b = fred(99)
eval("param", b.binding)
Show source
static VALUE
proc_binding(VALUE self)
{
rb_proc_t *proc;
VALUE bindval;
rb_binding_t *bind;
GetProcPtr(self, proc);
if (TYPE(proc->block.iseq) == T_NODE) {
if (!IS_METHOD_PROC_NODE((NODE *)proc->block.iseq)) {
rb_raise(rb_eArgError, "Can't create Binding from C level Proc");
}
}
bindval = binding_alloc(rb_cBinding);
GetBindingPtr(bindval, bind);
bind->env = proc->envval;
if (RUBY_VM_NORMAL_ISEQ_P(proc->block.iseq)) {
bind->filename = proc->block.iseq->filename;
bind->line_no = rb_iseq_first_lineno(proc->block.iseq);
}
else {
bind->filename = Qnil;
bind->line_no = 0;
}
return bindval;
}