file1
requires file2
, and I want to be able to cancel evaluating file2
under certain conditions without exiting the whole process.
# file1.rb
puts "In file 1"
require 'file2'
puts "Back in file 1"
# file2.rb
puts "In file 2"
# return if some_conditional
puts "Still in file 2"
When running file1
, the output I want to see is:
In file 1
In file 2
Back in file 1
The goal is for Still in file 2
to never print, while Back in file 1
does print. Is there anything I can do in file2
to make this possible?
I can't use exit
/exit!
/abort
here because Back in file 1
will never print. I could use raise
/fail
, but to do that I would have to change file1
and rescue
the failed require
. I'm hoping to find a way that doesn't involve altering file1
.
UPDATE:
A "top-level return" feature has been added.
A
infile2.rb
not to be part of the code. That is trivial. And it does not seem to make sense to have a code written in a file that you don't want to be executed. Is the part afterA
to be executed under any occasion? – Textualism