try_convert

IO.try_convert(obj) â io or nil Class Public methods Try to convert obj into an IO, using #to_io method. Returns converted IO or nil if obj cannot be converted for any reason. IO.try_convert(STDOUT) #=> STDOUT IO.try_convert("STDOUT") #=> nil require 'zlib' f = open("/tmp/zz.gz") #=> #<File:/tmp/zz.gz> z = Zlib::GzipReader.open(f) #=> #<Zlib::GzipReader:0x81d8744> IO.try_convert(z) #=> #<File:/tmp/zz.gz>

sysopen

IO.sysopen(path, [mode, [perm]]) â fixnum Class Public methods Opens the given path, returning the underlying file descriptor as a Fixnum. IO.sysopen("testfile") #=> 3

select

IO.select(read_array[, write_array[, error_array[, timeout]]]) â array or nil Class Public methods Calls select(2) system call. It monitors given arrays of IO objects, waits one or more of IO objects ready for reading, are ready for writing, and have pending exceptions respectably, and returns an array that contains arrays of those IO objects. It will return nil if optional timeout value is given and no IO object is ready in timeout seconds. Parameters read_array an array of

readlines

IO.readlines(name, sep=$/ [, open_args]) â arrayIO.readlines(name, limit [, open_args]) â arrayIO.readlines(name, sep, limit [, open_args]) â array Class Public methods Reads the entire file specified by name as individual lines, and returns those lines in an array. Lines are separated by sep. a = IO.readlines("testfile") a[0] #=> "This is line one\n" If the last argument is a hash, it's the keyword argument to open. See IO.read for detail.

read

IO.read(name, [length [, offset]] ) â stringIO.read(name, [length [, offset]], open_args) â string Class Public methods 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

popen

IO.popen([env,] cmd, mode="r" [, opt]) â ioIO.popen([env,] cmd, mode="r" [, opt]) {|io| block } â obj Class Public methods Runs the specified command as a subprocess; the subprocess's standard input and output will be connected to the returned IO object. The PID of the started process can be obtained by #pid method. cmd is a string or an array as follows. cmd: "-" : fork commandline : command line

pipe

IO.pipe â [read_io, write_io]IO.pipe(ext_enc) â [read_io, write_io]IO.pipe("ext_enc:int_enc" [, opt]) â [read_io, write_io]IO.pipe(ext_enc, int_enc [, opt]) â [read_io, write_io]IO.pipe(...) {|read_io, write_io| ... } Class Public methods Creates a pair of pipe endpoints (connected to each other) and returns them as a two-element array of IO objects: [ read_io, write_io ]. If a block is given, the block is called and returns th

open

IO.open(fd, mode="r" [, opt]) â ioIO.open(fd, mode="r" [, opt]) { |io| block } â obj Class Public methods With no associated block, IO.open is a synonym for ::new. If the optional code block is given, it will be passed io as an argument, and the IO object will automatically be closed when the block terminates. In this instance, ::open returns the value of the block. See ::new for a description of the fd, mode and opt parameters.

new

IO.new(fd [, mode] [, opt]) â io Class Public methods Returns a new IO object (a stream) for the given integer file descriptor fd and mode string. opt may be used to specify parts of mode in a more readable fashion. See also ::sysopen and ::for_fd. ::new is called by various File and IO opening methods such as ::open, Kernel#open, and File.open. Open Mode When mode is an integer it must be combination of the modes defined in File::Constants (File::RDONLY, +File::WRONLY | File:

foreach

IO.foreach(name, sep=$/ [, open_args]) {|line| block } â nilIO.foreach(name, limit [, open_args]) {|line| block } â nilIO.foreach(name, sep, limit [, open_args]) {|line| block } â nilIO.foreach(...) â an_enumerator Class Public methods Executes the block for every line in the named I/O port, where lines are separated by sep. If no block is given, an enumerator is returned instead. IO.foreach("testfile") {|x| print "GOT ", x } pr