Method: Kernel#iterator?
- Defined in:
- vm_eval.c
#block_given? ⇒ Boolean #iterator? ⇒ Boolean
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 #=> "no block"
try { "hello" } #=> "hello"
try do "hello" end #=> "hello"
2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 |
# File 'vm_eval.c', line 2444
static VALUE
rb_f_block_given_p(VALUE _)
{
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;
}
}
|