Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
File.open("example.txt", "w") do |file|
file.puts "This is a sample text file."
file.puts "Written with Ruby!"
end
puts "File written successfully."
puts "Reading file contents:"
File.readlines("example.txt").each_with_index do |line, index|
puts "#{index + 1}: #{line.strip}"
endCoding works best on desktop or with an external keyboard.