Ruby File.openモードとオプションとは何ですか?


186

Ruby File.openはモードとオプションを引数として受け取ります。モードとオプションの完全なリストはどこにありますか?


ruby-doc.org/core-2.0.0/IO.html#method-c-new-label-IO+Open+Mode-このページへのリンクは以下のダニエルズの回答にありますが、ページをスクロールしてアクセスする必要がありますそれ。これは、ドキュメントの関連部分への直接リンクです。
newUserNameHere 2013年

回答:


377

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

2
萌えのリストをありがとう。しかし、オプションのリストはどこにありますか:File.open(filename、mode = "r" [、opt])=> file
never_had_a_name

1
どこで見つけたの?残念ながら、File.open(filename, mode="r" [, opt])ドキュメントでは見つかりません。
Daniel O'Hara

@floatless。FileクラスのAPI。クラス「ファイル」に移動し、メソッド「開く」をクリックします。
never_had_a_name

1
まだ実験段階であり、まだ実装されていません。そして、私はまだあなたが話すAPIについて理解していません。リンクを貼ってください。
Nakilon

1
「a +」に少しだけ追加すると、ファイルの終わりではなく、ファイルの最初から読み取りが始まります(誰かが疑問に思った場合に備えて)。
yoppuyoppu

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.