How to unwind (multi-level return) the stack without catch/try/raise?

650 views Asked by At

I would like to unwind the stack to an arbitrary level when catch/try is not available (i.e., the code to which I'm unwinding is out of my control). Is this possible?

For example, in testing, I would like to have my tests call a method that checks for prerequisites, and unwinds to the caller of the test if those prereqs aren't met (resume at caller[1]). Since the test harness is out of my control, I can't set up a catch block at the appropriate place.

1

There are 1 answers

2
Michiel de Mare On BEST ANSWER

No. The only other mechanism for multi-level returns is callcc, but that too requires creating the continuation at a level that's out of your control.

That said, in Ruby nothing is really out of your control: you could alias the method in the test framework and add any code you'd like.