Ruby 2.7.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > FileTestモジュール > writable?

module function FileTest.#writable?

writable?(file) -> bool[permalink][rdoc]

ファイルがカレントプロセスにより書き込み可能である時に真を返します。そうでない場合、ファイルが存在しない場合、あるいはシステムコールに失敗した場合などには false を返します。

[PARAM] file:
ファイル名を表す文字列を指定します。


IO.write("testfile", "test")
File.chmod(0600, "testfile")
FileTest.writable?("testfile")      # => true
File.chmod(0400, "testfile")
FileTest.writable?("testfile")      # => false