mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[DOC] Enhanced RDOc for IO (#6642)
In io.c treats: #close #close_read #close_write #closed
This commit is contained in:
parent
572cd10a86
commit
91c28ab2ee
Notes:
git
2022-10-29 19:47:41 +00:00
Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2 changed files with 89 additions and 31 deletions
|
@ -189,14 +189,13 @@ The relevant methods:
|
||||||
|
|
||||||
A new \IO stream may be open for reading, open for writing, or both.
|
A new \IO stream may be open for reading, open for writing, or both.
|
||||||
|
|
||||||
You can close a stream using these methods:
|
A stream is automatically closed when claimed by the garbage collector.
|
||||||
|
|
||||||
|
Attempted reading or writing on a closed stream raises an exception.
|
||||||
|
|
||||||
- IO#close: Closes the stream for both reading and writing.
|
- IO#close: Closes the stream for both reading and writing.
|
||||||
- IO#close_read (not in \ARGF): Closes the stream for reading.
|
- IO#close_read: Closes the stream for reading; not in ARGF.
|
||||||
- IO#close_write (not in \ARGF): Closes the stream for writing.
|
- IO#close_write: Closes the stream for writing; not in ARGF.
|
||||||
|
|
||||||
You can query whether a stream is closed using this method:
|
|
||||||
|
|
||||||
- IO#closed?: Returns whether the stream is closed.
|
- IO#closed?: Returns whether the stream is closed.
|
||||||
|
|
||||||
==== End-of-Stream
|
==== End-of-Stream
|
||||||
|
|
109
io.c
109
io.c
|
@ -5637,13 +5637,31 @@ rb_io_close(VALUE io)
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* close -> nil
|
* close -> nil
|
||||||
*
|
*
|
||||||
* Closes the stream, if it is open, after flushing any buffered writes
|
* Closes the stream for both reading and writing
|
||||||
* to the operating system; does nothing if the stream is already closed.
|
* if open for either or both; returns +nil+.
|
||||||
* A stream is automatically closed when claimed by the garbage collector.
|
|
||||||
*
|
*
|
||||||
* If the stream was opened by IO.popen, #close sets global variable <tt>$?</tt>.
|
* If the stream is open for writing, flushes any buffered writes
|
||||||
|
* to the operating system before closing.
|
||||||
*
|
*
|
||||||
* See also {Open and Closed Streams}[rdoc-ref:io_streams.rdoc@Open+and+Closed+Streams].
|
* If the stream was opened by IO.popen, sets global variable <tt>$?</tt>
|
||||||
|
* (child exit status).
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* IO.popen('ruby', 'r+') do |pipe|
|
||||||
|
* puts pipe.closed?
|
||||||
|
* pipe.close
|
||||||
|
* puts $?
|
||||||
|
* puts pipe.closed?
|
||||||
|
* end
|
||||||
|
*
|
||||||
|
* Output:
|
||||||
|
*
|
||||||
|
* false
|
||||||
|
* pid 13760 exit 0
|
||||||
|
* true
|
||||||
|
*
|
||||||
|
* Related: IO#close_read, IO#close_write, IO#closed?.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -5694,17 +5712,23 @@ io_close(VALUE io)
|
||||||
* Returns +true+ if the stream is closed for both reading and writing,
|
* Returns +true+ if the stream is closed for both reading and writing,
|
||||||
* +false+ otherwise:
|
* +false+ otherwise:
|
||||||
*
|
*
|
||||||
* f = File.new('t.txt')
|
* IO.popen('ruby', 'r+') do |pipe|
|
||||||
* f.close # => nil
|
* puts pipe.closed?
|
||||||
* f.closed? # => true
|
* pipe.close_read
|
||||||
* f = IO.popen('/bin/sh','r+')
|
* puts pipe.closed?
|
||||||
* f.close_write # => nil
|
* pipe.close_write
|
||||||
* f.closed? # => false
|
* puts pipe.closed?
|
||||||
* f.close_read # => nil
|
* end
|
||||||
* f.closed? # => true
|
|
||||||
*
|
*
|
||||||
|
* Output:
|
||||||
|
*
|
||||||
|
* false
|
||||||
|
* false
|
||||||
|
* true
|
||||||
*
|
*
|
||||||
* See also {Open and Closed Streams}[rdoc-ref:io_streams.rdoc@Open+and+Closed+Streams].
|
* See also {Open and Closed Streams}[rdoc-ref:io_streams.rdoc@Open+and+Closed+Streams].
|
||||||
|
*
|
||||||
|
* Related: IO#close_read, IO#close_write, IO#close.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -5731,17 +5755,33 @@ rb_io_closed(VALUE io)
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* close_read -> nil
|
* close_read -> nil
|
||||||
*
|
*
|
||||||
* Closes the read end of a duplexed stream (i.e., one that is both readable
|
* Closes the stream for reading if open for reading;
|
||||||
* and writable, such as a pipe); does nothing if already closed:
|
* returns +nil+.
|
||||||
*
|
*
|
||||||
* f = IO.popen('/bin/sh','r+')
|
* If the stream was opened by IO.popen and is also closed for writing,
|
||||||
* f.close_read
|
* sets global variable <tt>$?</tt> (child exit status).
|
||||||
* f.readlines # Raises IOError
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* IO.popen('ruby', 'r+') do |pipe|
|
||||||
|
* puts pipe.closed?
|
||||||
|
* pipe.close_write
|
||||||
|
* puts pipe.closed?
|
||||||
|
* pipe.close_read
|
||||||
|
* puts $?
|
||||||
|
* puts pipe.closed?
|
||||||
|
* end
|
||||||
|
*
|
||||||
|
* Output:
|
||||||
|
*
|
||||||
|
* false
|
||||||
|
* false
|
||||||
|
* pid 14748 exit 0
|
||||||
|
* true
|
||||||
*
|
*
|
||||||
* See also {Open and Closed Streams}[rdoc-ref:io_streams.rdoc@Open+and+Closed+Streams].
|
* See also {Open and Closed Streams}[rdoc-ref:io_streams.rdoc@Open+and+Closed+Streams].
|
||||||
*
|
*
|
||||||
* Raises an exception if the stream is not duplexed.
|
* Related: IO#close, IO#close_write, IO#closed?.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -5789,14 +5829,33 @@ rb_io_close_read(VALUE io)
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* close_write -> nil
|
* close_write -> nil
|
||||||
*
|
*
|
||||||
* Closes the write end of a duplexed stream (i.e., one that is both readable
|
* Closes the stream for writing if open for writing;
|
||||||
* and writable, such as a pipe); does nothing if already closed:
|
* returns +nil+:
|
||||||
*
|
*
|
||||||
* f = IO.popen('/bin/sh', 'r+')
|
* Flushes any buffered writes to the operating system before closing.
|
||||||
* f.close_write
|
*
|
||||||
* f.print 'nowhere' # Raises IOError.
|
* If the stream was opened by IO.popen and is also closed for reading,
|
||||||
|
* sets global variable <tt>$?</tt> (child exit status).
|
||||||
|
*
|
||||||
|
* IO.popen('ruby', 'r+') do |pipe|
|
||||||
|
* puts pipe.closed?
|
||||||
|
* pipe.close_read
|
||||||
|
* puts pipe.closed?
|
||||||
|
* pipe.close_write
|
||||||
|
* puts $?
|
||||||
|
* puts pipe.closed?
|
||||||
|
* end
|
||||||
|
*
|
||||||
|
* Output:
|
||||||
|
*
|
||||||
|
* false
|
||||||
|
* false
|
||||||
|
* pid 15044 exit 0
|
||||||
|
* true
|
||||||
*
|
*
|
||||||
* See also {Open and Closed Streams}[rdoc-ref:io_streams.rdoc@Open+and+Closed+Streams].
|
* See also {Open and Closed Streams}[rdoc-ref:io_streams.rdoc@Open+and+Closed+Streams].
|
||||||
|
*
|
||||||
|
* Related: IO#close, IO#close_read, IO#closed?.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
|
Loading…
Reference in a new issue