Ruby exercise in writing and reading a file [closed]

I've been asked to improve the modular decomposition of the main by moving as many lines of code out of main as possible, but i have no idea how i should do this

# writes the number of lines then each line as a string.
def write_data_to_file(aFile)
aFile.puts('5')
end

puts aFile.gets
end

# writes data to a file then reads it in and prints each line as it reads
def main
aFile = File.new("mydata.txt", "w") # open for writing
if aFile  # if nil this test will be false
write_data_to_file(aFile)
aFile.close
else
puts "Unable to open file to write!"
end

aFile = File.new("mydata.txt", "r") # open for reading
if aFile  # if nil this test will be false
$$$$
• Welcome to Code Review. Try putting a newline after the closing . The title should reflect what the code is to achieve, see How do I ask a Good Question? – greybeard May 15 at 6:22