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

nev*_*ame 176 ruby file-io

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

Dan*_*ara 358

我想在Ruby IO模块文档中.

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").
Run Code Online (Sandbox Code Playgroud)

  • 感谢您提供的帮助清单。但是这些选项的列表在哪里:File.open(filename,mode =“ r” [,opt])=&gt; file (2认同)

Sha*_*ell 6

opt对于ruby 1.9来说是新的.各种选项记录在IO.new:www.ruby-doc.org/core/IO.html