Type:
Class
Constants:
SEEK_SET : INT2FIX(SEEK_SET)
SEEK_CUR : INT2FIX(SEEK_CUR)
SEEK_END : INT2FIX(SEEK_END)

Expect library adds the IO instance method expect, which does similar act to tcl's expect extension.

In order to use this method, you must require expect:

require 'expect'

Please see expect for usage.

The IO class is the basis for all input and output in Ruby. An I/O stream may be duplexed (that is, bidirectional), and so may use more than one native operating system stream.

Many of the examples in this section use the File class, the only standard subclass of IO. The two classes are closely associated. Like the File class, the Socket library subclasses from IO (such as TCPSocket or UDPSocket).

The Kernel#open method can create an IO (or File) object for these types of arguments:

  • A plain string represents a filename suitable for the underlying operating system.

  • A string starting with "|" indicates a subprocess. The remainder of the string following the "|" is invoked as a process with appropriate input/output channels connected to it.

  • A string equal to "|-" will create another Ruby instance as a subprocess.

The IO may be opened with different file modes (read-only, write-only) and encodings for proper conversion. See ::new for these options. See Kernel#open for details of the various command formats described above.

::popen, the Open3 library, or Process#spawn may also be used to communicate with subprocesses through an IO.

Ruby will convert pathnames between different operating system conventions if possible. For instance, on a Windows system the filename "/gumby/ruby/test.rb" will be opened as "\gumby\ruby\test.rb". When specifying a Windows-style filename in a Ruby string, remember to escape the backslashes:

"c:\\gumby\\ruby\\test.rb"

Our examples here will use the Unix-style forward slashes; File::ALT_SEPARATOR can be used to get the platform-specific separator character.

The global constant ARGF (also accessible as $<) provides an IO-like stream which allows access to all files mentioned on the command line (or STDIN if no files are mentioned). ARGF#path and its alias ARGF#filename are provided to access the name of the file currently being read.

io/console

The io/console extension provides methods for interacting with the console. The console can be accessed from ::console or the standard input/output/error IO objects.

Requiring io/console adds the following methods:

Example:

require 'io/console'
rows, columns = $stdin.winsize
puts "Your screen is #{columns} wide and #{rows} tall"
lineno=

ios.lineno = integer â integer Instance Public methods Manually sets the

2015-04-13 12:37:17
rewind

ios.rewind â 0 Instance Public methods Positions ios to the beginning

2015-04-13 14:01:44
getch

io.getch(min: nil, time: nil) â char Instance Public methods Reads and

2015-04-13 12:03:43
pipe

IO.pipe â [read_io, write_io]IO.pipe(ext_enc) â [read_io, write_io]IO.pipe("ext_enc:int_enc" [, opt])

2015-04-13 09:14:45
binwrite

IO.binwrite(name, string, [offset] ) => fixnumIO.binwrite(name, string, [offset], open_args ) => fixnum

2015-04-13 08:33:31
cooked

io.cooked {|io| } Instance Public methods Yields self within cooked

2015-04-13 10:44:05
sysopen

IO.sysopen(path, [mode, [perm]]) â fixnum Class Public methods Opens the given

2015-04-13 09:35:49
seek

ios.seek(amount, whence=IO::SEEK_SET) â 0 Instance Public methods Seeks to

2015-04-13 14:10:30
external_encoding

io.external_encoding â encoding Instance Public methods Returns the

2015-04-13 11:28:19
readlines 2

ios.readlines(sep=$/) â arrayios.readlines(limit) â arrayios.readlines(sep, limit) â array

2015-04-13 13:51:46