# 'w' denotes "write mode".
File.open('file.txt', 'w') do |file|
  file.puts 'Wrote some text.'
end	# File is automatically closed here
 
File.readlines('file.txt').each do |line|
  puts line
end
# => Wrote some text.