Ruby Serial Program Execution

Hello:

I am new to Ruby and experimenting. I have a process broken down
into five individual Ruby programs. I have contained each of the five
within another single Ruby program as follows:

require_relative ‘Step1.rb’
require_relative ‘Step2.rb’
require_relative ‘Step3.rb’
require_relative ‘Step4.rb’
require_relative ‘Step5.rb’

The Step5.rb program which is the last program in the sequence writes
out
a file. It does this perfectly when I execute Step5.rb all by itself
giving me the file and the content I want.

But when I execute the five steps within the containing .rb program, the
Step5.rb program creates the file but has nothing in it.

My question is this, in the containing program [let’s call it Phase1.rb,
do the programs contained execute and complete serially [which is what I
want], or do I have to do something else to make sure each Step is
completed before the next executed?

Dave B. wrote in post #1169577:

My question is this, in the containing program [let’s call it Phase1.rb,
do the programs contained execute and complete serially [which is what I
want], or do I have to do something else to make sure each Step is
completed before the next executed?

They should be - but of course we do not know what’s in those files.
Keep in mind though that there is a difference between executing a
script individually and having it execute as part of a larger script.

Typically one would distribute logic across different classes and put
those in separate files.

One last thing: require and require_relative are used to load parts of
code, not to execute something right there. They will only load a file
once per process even if invoked multiple times. For that you would
rather use load. But, as said above, you should better follow a
different approach altogether.