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

I would like to spin the stack to an arbitrary level when catch / try not available (i.e. the code I'm deploying is out of control). Is it possible?

For example, during testing, I would like my tests to call a method that checks the preconditions, and unwind the caller if these preconditions are not met (resume in caller[1] ). Since the test harness failed, I cannot configure the catch in the appropriate place.

+4
source share
1 answer

No. The only other mechanism for tiered returns is callcc , but it also requires creating a continuation at a level that is not controlled.

However, nothing came out of your control in Ruby: you could have a method alias in a test environment and add whatever code you would like.

+1
source

Source: https://habr.com/ru/post/1339841/


All Articles