iterator?()
public
Returns true if yield would execute a block in the current context. The iterator? form is mildly deprecated.
def try
if block_given?
yield
else
"no block"
end
end
try
try { "hello" }
try do "hello" end
Show source
static VALUE
rb_f_block_given_p(void)
{
rb_execution_context_t *ec = GET_EC();
rb_control_frame_t *cfp = ec->cfp;
cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
if (cfp != NULL && VM_CF_BLOCK_HANDLER(cfp) != VM_BLOCK_HANDLER_NONE) {
return Qtrue;
}
else {
return Qfalse;
}
}