Method: Kernel#callcc

Defined in:
cont.c

#callcc {|cont| ... } ⇒ Object

Generates a Continuation object, which it passes to the associated block. You need to require 'continuation' before using this method. Performing a cont.call will cause the #callcc to return (as will falling through the end of the block). The value returned by the #callcc is the value of the block, or the value passed to cont.call. See class Continuation for more details. Also see Kernel#throw for an alternative mechanism for unwinding a call stack.

Yields:

  • (cont)

Returns:

[View source]

1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
# File 'cont.c', line 1524

static VALUE
rb_callcc(VALUE self)
{
    volatile int called;
    volatile VALUE val = cont_capture(&called);

    if (called) {
        return val;
    }
    else {
        return rb_yield(val);
    }
}