Use the __END__
keyword to stop the parser.
puts "My Script is running!"
__END__
puts "This will never happen"
...
Or just comment out the rest of the script (if you need the a well-formed DATA
stream after the ___END__
)
puts "My Script is running!"
=begin
puts "This will never happen"
...
=end
If you need to exit early based on logic rather than at a fixed point, you could put the body of the script in a function and just return early.
def do_work
puts "My Script is running!"
...
return if exit_condition?
puts "This will never happen if exit condition is true"
...
end
do_work
Alternatively, put your script in a begin block and rescue an exception you raise
begin
puts "My Script is running!"
raise SystemExit if exit_condition?
puts "This will never happen if exit condition is true"
rescue SystemExit
end