File operations in Ruby

Submitted by Karthikeyan on Sat, 20/10/2012 - 07:07
File concepts in Ruby This Ruby program opens file in write mode and writes text in it. Then opens the program in read mode and reads the contents. Code:'test.txt','w') do |f1|
  f1.puts "Welcome to"
  f1.puts "Thank you! Visit Again"
end'test.txt','r') do |f2|
  while line=f2.gets
    puts line

Welcome to
Thank you! Visit Again