4

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.

sawa
  • 165,429
  • 45
  • 277
  • 381
RoUS
  • 1,888
  • 2
  • 14
  • 29

1 Answers1

1

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.

Michiel de Mare
  • 41,982
  • 29
  • 103
  • 134