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 (RB_TYPE_P((VALUE)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 = rb_binding_alloc(rb_cBinding);
GetBindingPtr(bindval, bind);
bind->env = proc->envval;
bind->blockprocval = proc->blockprocval;
if (RUBY_VM_NORMAL_ISEQ_P(proc->block.iseq)) {
bind->path = proc->block.iseq->location.path;
bind->first_lineno = FIX2INT(rb_iseq_first_lineno(proc->block.iseq->self));
}
else {
bind->path = Qnil;
bind->first_lineno = 0;
}
return bindval;
}