Name

IO — I/O class

Synopsis

IO is object-oriented representation of stdio. IO is a superclass of other IO related classes, such as File, BasicSocket, etc.

Included Module

Enumerable

Class Methods

IO::foreach(path) {|x|...}

Opens the file and executes the block once for each line, closing the file when the block exits.

n = 1
IO::foreach(path) {|line|
  print n, ":", lib
  n+=1
}
IO::new(fd[,mode="r"])

Returns a new IO stream for the specified integer file descriptor fd.

IO::pipe

Creates a pair of IO streams connected to each other and returns them as an array ([readIO, writeIO]).

IO::popen(cmd[,mode="r"])
IO::popen(cmd[,mode="r"]) {|io|...}

Executes the command specified by cmd as a subprocess and creates an associated stream connected to it. If cmd is -, a new instance of Ruby is started as a subprocess with an IO object returned in the parent and nil returned in the child process. If a block is specified, it’s run with the IO object as a parameter. The stream is closed when the block exits.

IO::readlines(path)

Returns the contents of a file as an array of strings.

IO::select(reads[, writes=nil[, excepts=nil[,timeout=nil]]])

Checks for changes in the status of three types of IO objects, input, output, and exceptions, which are passed as arrays of IO objects. nil is passed for arguments that don’t need checking. A three-element array containing arrays of the IO objects for which there were changes in status is returned. nil is returned on timeout.

IO::select([STDIN], nil, nil, 1.5) # wair data ...

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.