0 votes
in Ruby by
How to read a file in Ruby?

1 Answer

0 votes
by
There are three different methods to read a file.

To return a single line, following syntax is used.

Syntax:

f.gets  

code...  

To return the whole file after the current position, following syntax is used.

Syntax:

f.rea  

code...  

To return file as an array of lines, following syntax is used.

Syntax:

f.readlines  

[code...]
...