The IO instance is used for all input and output operations in Ruby. When we use the readlines() method to read a file, it returns individual lines of a file as an array.
IO.readlines(filename)
filename: This is the name of the file. This method returns an array containing individual lines of the file filename.
Let's look at the code below:
Welcome to edpressoPlease to meet you!Happy learning!
We create a file named text.txt and write some contents in it:
readlines() method to get the contents of the file we created, line by line, as an array.