Project

General

Profile

Actions

Bug #7179

closed

IO doc: wrong/misleading text for mode

Added by roman-neuhauser (Roman Neuhauser) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Backport:
[ruby-core:48052]

Description

affects also 1.9.2, 1.9.1, 1.8.7

http://www.ruby-doc.org/core-1.9.3/IO.html makes the impression
that "b" and "t" are valid on their own, when in fact they're
modifiers and need to be preceded by one of the "real" modes
(a, r, w, and the + variants):

If the mode is given as a String, it must be one of the values
listed in the following table.

notice that "b" and "t" are among the listed values, so they're
clearly permissible, right? (those "may appear" are also quite
clear: "may" implies "does not need to").

Mode |  Meaning
-----+--------------------------------------------------------
"r"  |  Read-only, starts at beginning of file  (default mode).
-----+--------------------------------------------------------
"r+" |  Read-write, starts at beginning of file.
-----+--------------------------------------------------------
"w"  |  Write-only, truncates existing file
     |  to zero length or creates a new file for writing.
-----+--------------------------------------------------------
"w+" |  Read-write, truncates existing file to zero length
     |  or creates a new file for reading and writing.
-----+--------------------------------------------------------
"a"  |  Write-only, starts at end of file if file exists,
     |  otherwise creates a new file for writing.
-----+--------------------------------------------------------
"a+" |  Read-write, starts at end of file if file exists,
     |  otherwise creates a new file for reading and
     |  writing.
-----+--------------------------------------------------------
 "b" |  Binary file mode (may appear with
     |  any of the key letters listed above).
     |  Suppresses EOL <-> CRLF conversion on Windows. And
     |  sets external encoding to ASCII-8BIT unless explicitly
     |  specified.
-----+--------------------------------------------------------
 "t" |  Text file mode (may appear with
     |  any of the key letters listed above except "b").

i suggest splitting the table into two and adding a bit of prose
explicitly saying that "b" and "t" cannot be used on their own.

background: i found a few occurrences of File.open(..., "b")
in code by a seasoned ruby programmer who assumed "r" was implied
in this situation.

Actions

Also available in: Atom PDF

Like0
Like0