Question : Ruby - writing data from array to file

Hello
My following script is only dumping first line to a file - where as it should contain many hundreds - can someone correct my attempt please.

P

File.open("U:/Phil_Sivyer/4_B_Man_hours_lost/Availability_daily_BAC/AVAILABILITY_joined.txt").each do |line|
  a = line.gsub('Availability','')
 
   sink = File.open("U:/Phil_Sivyer/4_B_Man_hours_lost/Availability_daily_BAC/zzAVAILABILITY_joined.txt", "w")
   b = a.each do |phil|
   sink.write(phil)
 sink.close
end
 end

Answer : Ruby - writing data from array to file

I think it only dumps the last line, since you are constantly opening an closing the file for writing.
You should put the sink = file.open outside the loop
and a is not an array, but a single item, so th eb loop is not necessary

untested:
sink = File.open("U:/Phil_Sivyer/4_B_Man_hours_lost/Availability_daily_BAC/zzAVAILABILITY_joined.txt", "w")
 File.open("U:/Phil_Sivyer/4_B_Man_hours_lost/Availability_daily_BAC/AVAILABILITY_joined.txt").each do |line|
    sink.write line.gsub('Availability','')
end
sink.close
Random Solutions  
 
programming4us programming4us