v2_1_10 - Show latest stable - 0 notes - Class: ARGF
read(p1 = v1, p2 = v2) public

Reads length bytes from ARGF. The files named on the command line are concatenated and treated as a single file by this method, so when called without arguments the contents of this pseudo file are returned in their entirety.

length must be a non-negative integer or nil. If it is a positive integer, read tries to read at most length bytes. It returns nil if an EOF was encountered before anything could be read. Fewer than length bytes may be returned if an EOF is encountered during the read.

If length is omitted or is nil, it reads until EOF. A String is returned even if EOF is encountered before any data is read.

If length is zero, it returns _“”_.

If the optional outbuf argument is present, it must reference a String, which will receive the data. The outbuf will contain only the received data after the method call even if it is not empty at the beginning.

For example:

$ echo "small" > small.txt
$ echo "large" > large.txt
$ ./glark.rb small.txt large.txt      #=> "small\nlarge" #=> "small\nlarge"   #=> "sm"   #=> ""

Note that this method behaves like fread() function in C. If you need the behavior like read(2) system call, consider ARGF.readpartial.

Show source
Register or log in to add new notes.