Ruby defines a single base class,
, to handle input and output.
This base class is subclassed by classes
to provide more specialized behavior, but the
principles are the same throughout. An
object is a bidirectional
channel between a Ruby program and some external resource.[For those
who just have to know the implementation details, this means that a
IO object can sometimes be managing more than one operating
system file descriptor. For example, if you open a pair of pipes, a
IO object contains both a read pipe and a write pipe.]
There may be more to an
object than meets the eye, but in the
end you still simply write to it and read from it.
In this chapter, we'll be concentrating on class
and its most
commonly used subclass, class
. For more details on using the
socket classes for networking, see the section beginning on page 469.