Question : RUBY - RESULTS TO .TXT FILE

Hello
New to Ruby!
If I create a simple script whereby I want the results (when run) to be saved out to a .txt file
How is this done - my script, for now, is as follows ........
line_count = 0
File.open("c:/phil.txt").each { | line | line_count += 1 }
puts line_count

Phil

Answer : RUBY - RESULTS TO .TXT FILE

add this to the end of your script

File.open("linecnt.txt", "w") do |sink|
 sink.write line_count.to_s
end
Random Solutions  
 
programming4us programming4us