ChatGPT解决这个技术问题 Extra ChatGPT

Ruby File.open 模式和选项是什么?

Ruby 的 File.open 将模式和选项作为参数。在哪里可以找到模式和选项的完整列表?

ruby-doc.org/core-2.0.0/IO.html#method-c-new-label-IO+Open+Mode - 此页面的链接在下面的 Daniels 答案中,但您必须滚动页面才能找到它。这是文档相关部分的直接链接。

C
Casimir et Hippolyte

我想在 Ruby IO module documentation 中。

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").

感谢moes的名单。但是选项列表在哪里: File.open(filename, mode="r" [, opt]) => file
你是在哪里找到那个东西的。不幸的是,我在文档中找不到 File.open(filename, mode="r" [, opt])
@floatless。在 File 类的 api 中。转到“文件”类,然后单击“打开”方法。
我想,这是一些实验性的,尚未实施。而且我仍然不明白你说的是什么 API。给个链接。
如果我可以为“a+”添加一点点,读取从文件的开头开始,而不是在文件的末尾(以防有人想知道)。
S
Shadwell

opt 是 ruby 1.9 的新功能。 IO.new 中记录了各种选项:www.ruby-doc.org/core/IO.html


不幸的是,该链接现在似乎已过时!