read(p1, p2 = v2, p3 = v3, p4 = v4) public

Opens the file, optionally seeks to the given offset, then returns length bytes (defaulting to the rest of the file). read ensures the file is closed before returning.

If the last argument is a hash, it specifies option for internal open(). The key would be the following. open_args: is exclusive to others.

encoding: string or encoding

specifies encoding of the read string.  encoding will be ignored
if length is specified.

mode: string

specifies mode argument for open().  it should start with "r"
otherwise it would cause error.

open_args: array of strings

specifies arguments for open() as an array.

 IO.read("testfile")           #=> "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
 IO.read("testfile", 20)       #=> "This is line one\nThi"
 IO.read("testfile", 20, 10)   #=> "ne one\nThis is line "
Show source
Register or log in to add new notes.