るりまサーチ (Ruby 2.4.0)

最速Rubyリファレンスマニュアル検索!
42件ヒット [1-42件を表示] (0.034秒)
トップページ > バージョン:2.4.0[x] > ライブラリ:ビルトイン[x] > クエリ:NIL[x] > クラス:IO[x] > クエリ:open[x]

別のキーワード

  1. _builtin nil?
  2. object nil?
  3. nilclass nil?
  4. object nil
  5. _builtin nil

キーワード

検索結果

IO.open(fd, mode = "r", **opts) -> IO (45424.0)

オープン済みのファイルディスクリプタ fd に対する新しい IO オブジェクトを生成して返します。

...オープン済みのファイルディスクリプタ fd に対する新しい
IO
オブジェクトを生成して返します。

IO
.open にブロックが与えられた場合、IO オブジェクトを生成しそれを引数としてブロックを
実行します。ブロックの終了と...
...ともに fd はクローズされます。ブロックの結果を返します。
IO
.new, IO.for_fd はブロックを受け付けません。

=== キーワード引数
このメソッドは以下のキーワード引数を利用できます。
* :mode mode引数と同じ意味です
* :extern...
...用いられます。


@param fd ファイルディスクリプタである整数を指定します。

@param mode Kernel.#open と同じ形式で IO のモードを指定します。File::Constants::RDONLY などの
定数(数値)でモードを指定できます。詳細は組み込...

IO.open(fd, mode = "r", **opts) {|io| ... } -> object (45424.0)

オープン済みのファイルディスクリプタ fd に対する新しい IO オブジェクトを生成して返します。

...オープン済みのファイルディスクリプタ fd に対する新しい
IO
オブジェクトを生成して返します。

IO
.open にブロックが与えられた場合、IO オブジェクトを生成しそれを引数としてブロックを
実行します。ブロックの終了と...
...ともに fd はクローズされます。ブロックの結果を返します。
IO
.new, IO.for_fd はブロックを受け付けません。

=== キーワード引数
このメソッドは以下のキーワード引数を利用できます。
* :mode mode引数と同じ意味です
* :extern...
...用いられます。


@param fd ファイルディスクリプタである整数を指定します。

@param mode Kernel.#open と同じ形式で IO のモードを指定します。File::Constants::RDONLY などの
定数(数値)でモードを指定できます。詳細は組み込...

IO.popen("-", mode = "r", opt={}) -> IO (18397.0)

第一引数に文字列 "-" が指定された時、fork(2) を 行い子プロセスの標準入出力との間にパイプラインを確立します。 親プロセスでは IO オブジェクトを返し、子プロセスでは nil を返します。

...ンを確立します。
親プロセスでは IO オブジェクトを返し、子プロセスでは
nil を返します。

io
= IO.popen("-", "r+")
if io # parent
io
.puts "foo"
p io.gets # => "child output: foo\n"
io
.close
else # child
s = gets
print...
... IO オブジェクトを引数に
ブロックを実行し、その結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。
子プロセスでは nil を引数にブロックを実行し終了します。

p IO.popen("-", "r+") {|io|...
...if io # parent
io
.puts "foo"
io
.gets
else # child
s = gets
puts "child output: " + s
end
}
# => "child output: foo\n"

opt ではエンコーディングの設定やプロセス起動のためのオプションが指定できます。
IO
.new や Kernel.#spa...

IO.popen("-", mode = "r", opt={}) {|io| ... } -> object (18397.0)

第一引数に文字列 "-" が指定された時、fork(2) を 行い子プロセスの標準入出力との間にパイプラインを確立します。 親プロセスでは IO オブジェクトを返し、子プロセスでは nil を返します。

...ンを確立します。
親プロセスでは IO オブジェクトを返し、子プロセスでは
nil を返します。

io
= IO.popen("-", "r+")
if io # parent
io
.puts "foo"
p io.gets # => "child output: foo\n"
io
.close
else # child
s = gets
print...
... IO オブジェクトを引数に
ブロックを実行し、その結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。
子プロセスでは nil を引数にブロックを実行し終了します。

p IO.popen("-", "r+") {|io|...
...if io # parent
io
.puts "foo"
io
.gets
else # child
s = gets
puts "child output: " + s
end
}
# => "child output: foo\n"

opt ではエンコーディングの設定やプロセス起動のためのオプションが指定できます。
IO
.new や Kernel.#spa...

IO.popen(env, "-", mode = "r", opt={}) -> IO (18397.0)

第一引数に文字列 "-" が指定された時、fork(2) を 行い子プロセスの標準入出力との間にパイプラインを確立します。 親プロセスでは IO オブジェクトを返し、子プロセスでは nil を返します。

...ンを確立します。
親プロセスでは IO オブジェクトを返し、子プロセスでは
nil を返します。

io
= IO.popen("-", "r+")
if io # parent
io
.puts "foo"
p io.gets # => "child output: foo\n"
io
.close
else # child
s = gets
print...
... IO オブジェクトを引数に
ブロックを実行し、その結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。
子プロセスでは nil を引数にブロックを実行し終了します。

p IO.popen("-", "r+") {|io|...
...if io # parent
io
.puts "foo"
io
.gets
else # child
s = gets
puts "child output: " + s
end
}
# => "child output: foo\n"

opt ではエンコーディングの設定やプロセス起動のためのオプションが指定できます。
IO
.new や Kernel.#spa...

絞り込み条件を変える

IO.popen(env, "-", mode = "r", opt={}) {|io| ... } -> object (18397.0)

第一引数に文字列 "-" が指定された時、fork(2) を 行い子プロセスの標準入出力との間にパイプラインを確立します。 親プロセスでは IO オブジェクトを返し、子プロセスでは nil を返します。

...ンを確立します。
親プロセスでは IO オブジェクトを返し、子プロセスでは
nil を返します。

io
= IO.popen("-", "r+")
if io # parent
io
.puts "foo"
p io.gets # => "child output: foo\n"
io
.close
else # child
s = gets
print...
... IO オブジェクトを引数に
ブロックを実行し、その結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。
子プロセスでは nil を引数にブロックを実行し終了します。

p IO.popen("-", "r+") {|io|...
...if io # parent
io
.puts "foo"
io
.gets
else # child
s = gets
puts "child output: " + s
end
}
# => "child output: foo\n"

opt ではエンコーディングの設定やプロセス起動のためのオプションが指定できます。
IO
.new や Kernel.#spa...

IO.popen([env = {}, [cmdname, arg0], *args, execopt={}], mode = "r", opt={}) -> IO (18337.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...ョンや、パイプ IO オブジェクトの属性(エンコーディングや
読み書き能力)を指定することができます。
プロセス起動のためのオプションは Kernel.#spawn と、
パイプオブジェクトの属性の指定のオプションは IO.new と共通です...

IO.popen([env = {}, [cmdname, arg0], *args, execopt={}], mode = "r", opt={}) {|f| ... } -> object (18337.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...ョンや、パイプ IO オブジェクトの属性(エンコーディングや
読み書き能力)を指定することができます。
プロセス起動のためのオプションは Kernel.#spawn と、
パイプオブジェクトの属性の指定のオプションは IO.new と共通です...

IO.popen([env = {}, cmdname, *args, execopt={}], mode = "r", opt={}) -> IO (18337.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...ョンや、パイプ IO オブジェクトの属性(エンコーディングや
読み書き能力)を指定することができます。
プロセス起動のためのオプションは Kernel.#spawn と、
パイプオブジェクトの属性の指定のオプションは IO.new と共通です...

IO.popen([env = {}, cmdname, *args, execopt={}], mode = "r", opt={}) {|f| ... } -> object (18337.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...ョンや、パイプ IO オブジェクトの属性(エンコーディングや
読み書き能力)を指定することができます。
プロセス起動のためのオプションは Kernel.#spawn と、
パイプオブジェクトの属性の指定のオプションは IO.new と共通です...

絞り込み条件を変える

IO.popen(env = {}, [[cmdname, arg0], *args, execopt={}], mode = "r", opt={}) -> IO (18337.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...ョンや、パイプ IO オブジェクトの属性(エンコーディングや
読み書き能力)を指定することができます。
プロセス起動のためのオプションは Kernel.#spawn と、
パイプオブジェクトの属性の指定のオプションは IO.new と共通です...

IO.popen(env = {}, [[cmdname, arg0], *args, execopt={}], mode = "r", opt={}) {|f| ... } -> object (18337.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...ョンや、パイプ IO オブジェクトの属性(エンコーディングや
読み書き能力)を指定することができます。
プロセス起動のためのオプションは Kernel.#spawn と、
パイプオブジェクトの属性の指定のオプションは IO.new と共通です...

IO.popen(env = {}, [cmdname, *args, execopt={}], mode = "r", opt={}) -> IO (18337.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...ョンや、パイプ IO オブジェクトの属性(エンコーディングや
読み書き能力)を指定することができます。
プロセス起動のためのオプションは Kernel.#spawn と、
パイプオブジェクトの属性の指定のオプションは IO.new と共通です...

IO.popen(env = {}, [cmdname, *args, execopt={}], mode = "r", opt={}) {|f| ... } -> object (18337.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...ョンや、パイプ IO オブジェクトの属性(エンコーディングや
読み書き能力)を指定することができます。
プロセス起動のためのオプションは Kernel.#spawn と、
パイプオブジェクトの属性の指定のオプションは IO.new と共通です...

IO.popen(env = {}, command, mode = "r", opt={}) -> IO (18337.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...ョンや、パイプ IO オブジェクトの属性(エンコーディングや
読み書き能力)を指定することができます。
プロセス起動のためのオプションは Kernel.#spawn と、
パイプオブジェクトの属性の指定のオプションは IO.new と共通です...

絞り込み条件を変える

IO.popen(env = {}, command, mode = "r", opt={}) {|f| ... } -> object (18337.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...ョンや、パイプ IO オブジェクトの属性(エンコーディングや
読み書き能力)を指定することができます。
プロセス起動のためのオプションは Kernel.#spawn と、
パイプオブジェクトの属性の指定のオプションは IO.new と共通です...

IO.read(path, length = nil, **opt) -> String | nil (841.0)

path で指定されたファイルを offset 位置から length バイト分読み込んで返します。

...場合は nil を返します。ただし、length に nil か 0 が指定されている場合は、空文字列 "" を返します。例えば、IO.read(空ファイル) は "" を返します。

引数 length が指定された場合はバイナリ読み込みメソッド、そうでない場合...
...e

IO
.open のモードを指定します。
"r" で始まる文字列である必要があります。

: :open_args

IO
.open に渡される引数を配列で指定します。

これらの他、 :external_encoding など
IO
.open のオプション引数が指定できます。

@see IO...
....binread

例:

IO
.read(empty_file) #=> ""
IO
.read(empty_file, 1) #=> nil
IO
.read(one_byte_file, 0, 10) #=> ""
IO
.read(one_byte_file, nil, 10) #=> ""
IO
.read(one_byte_file, 1, 10) #=> nil...

IO.read(path, length = nil, offset = 0, **opt) -> String | nil (841.0)

path で指定されたファイルを offset 位置から length バイト分読み込んで返します。

...場合は nil を返します。ただし、length に nil か 0 が指定されている場合は、空文字列 "" を返します。例えば、IO.read(空ファイル) は "" を返します。

引数 length が指定された場合はバイナリ読み込みメソッド、そうでない場合...
...e

IO
.open のモードを指定します。
"r" で始まる文字列である必要があります。

: :open_args

IO
.open に渡される引数を配列で指定します。

これらの他、 :external_encoding など
IO
.open のオプション引数が指定できます。

@see IO...
....binread

例:

IO
.read(empty_file) #=> ""
IO
.read(empty_file, 1) #=> nil
IO
.read(one_byte_file, 0, 10) #=> ""
IO
.read(one_byte_file, nil, 10) #=> ""
IO
.read(one_byte_file, 1, 10) #=> nil...

IO#read(length = nil, outbuf = "") -> String | nil (742.0)

length バイト読み込んで、その文字列を返します。

...の全てのデータを読み込んで、その文字列を返します。

@param outbuf 出力用のバッファを文字列で指定します。IO#read は読み込んだ
データをその文字列オブジェクトに上書きして返します。指定し
た文字...
...旦 length 長に拡張(ある
いは縮小)されたあと、実際に読み込んだデータのサイズになります。

@raise IOError 自身が読み込み用にオープンされていなければ発生します。

@raise Errno::EXXX データの読み込みに失敗した場...
...負の場合に発生します。

第二引数を指定した read の呼び出しでデータが空であった場合
(read が nil を返す場合)、outbuf は空文字列になります。

outbuf = "x" * 20;
io
= File.open("/dev/null")
p io.read(10,outbuf)
p outbuf
=> nil
""...

IO.binread(path, length = nil, offset = 0) -> String | nil (682.0)

path で指定したファイルを open し、offset の所まで seek し、 length バイト読み込みます。

...ist[例][ruby]{
IO
.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...\n")
IO
.binread("testfile") # => "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
IO
.binread("testfile", 20) # => "This is line one\nThi"
IO
.binread("test...
...file", 20, 10) # => "ne one\nThis is line "
//}

@see IO.read...

絞り込み条件を変える

IO.read(path, **opt) -> String | nil (541.0)

path で指定されたファイルを offset 位置から length バイト分読み込んで返します。

...場合は nil を返します。ただし、length に nil か 0 が指定されている場合は、空文字列 "" を返します。例えば、IO.read(空ファイル) は "" を返します。

引数 length が指定された場合はバイナリ読み込みメソッド、そうでない場合...
...e

IO
.open のモードを指定します。
"r" で始まる文字列である必要があります。

: :open_args

IO
.open に渡される引数を配列で指定します。

これらの他、 :external_encoding など
IO
.open のオプション引数が指定できます。

@see IO...
....binread

例:

IO
.read(empty_file) #=> ""
IO
.read(empty_file, 1) #=> nil
IO
.read(one_byte_file, 0, 10) #=> ""
IO
.read(one_byte_file, nil, 10) #=> ""
IO
.read(one_byte_file, 1, 10) #=> nil...

IO.foreach(path, rs = $/, chomp: false) {|line| ... } -> nil (415.0)

path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。

...][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.foreach("testfile") # => #<Enumerator: IO:foreach("testfile")>
IO
.foreach("testfile") { |x| print "GOT ", x }
# => GOT line1
# GOT line2,
# GOT line3
//}

//emlist[例:カンマを行の区切りに指定( rs = "," )][ruby]{
IO
.write("t...
...", "line1,line2,line3")
IO
.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}

//emlist[例: 各行の末尾から "\n", "\r", または "\r\n" を取り除く(chomp = true)][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.foreach("testfile", c...

IO#internal_encoding -> Encoding | nil (397.0)

IO の内部エンコーディングを返します。 内部エンコーディングが指定されていない場合は nil を返します。

...
IO
の内部エンコーディングを返します。
内部エンコーディングが指定されていない場合は nil を返します。

//emlist[例][ruby]{
IO
.write("testfile", "abcde")
File.open("testfile") do |f|
p f.internal_encoding # => nil
f.set_encoding("ASCII-8BIT", "EUC-JP"...

IO#external_encoding -> Encoding | nil (379.0)

IO の外部エンコーディングを返します。 外部エンコーディングが指定されていない場合は nil を返します。 ただし読み込み専用モードの場合は Encoding.default_external になります。

...
IO
の外部エンコーディングを返します。
外部エンコーディングが指定されていない場合は nil を返します。
ただし読み込み専用モードの場合は Encoding.default_external になります。

//emlist[例][ruby]{
IO
.write("testfile", "abcde")
File.ope...

IO#advise(advice, offset=0, len=0) -> nil (349.0)

posix_fadvise(2) を呼びだし、 ファイルへのアクセスパターンをOSに知らせます。

...表すシンボル
@param offset パターンを指定するデータの先頭位置
@param len パターンを指定するデータの長さ

@raise IOError ストリームが既に閉じられているときに発生する例外
@raise Errno::EBADF ファイルデスクリプタが不正である...

絞り込み条件を変える

IO.write(path, string, offset=nil, **opts) -> Integer (349.0)

path で指定されるファイルを開き、string を書き込み、 閉じます。

...キーワード引数はファイルを開くときに使われ、エンコーディングなどを指定することができます。
詳しくは IO.open を見てください。

@param path ファイル名文字列
@param string 書き込む文字列
@param offset 書き込み開始位置
@par...
...s line three\nAnd so on...\n"
IO
.write("testfile", text) # => 66
IO
.write("testfile", "0123456789", 20) #=> 10
IO
.read("testfile")
# => "This is line one\nThi0123456789two\nThis is line three\nAnd so on...\n"
IO
.write("testfile", "0123456789") #=> 10
IO
.read("testfile")...
...# => "0123456789"
//}

@see IO.binwrite...

IO#close -> nil (331.0)

入出力ポートをクローズします。

...ポートをクローズします。

以後このポートに対して入出力を行うと例外 IOError が発生しま
す。ガーベージコレクトの際にはクローズされていない IO ポートはクロー
ズされます。
self がパイプでプロセスにつながっていれ...
...se Errno::EXXX close に失敗した場合に発生します。

//emlist[例][ruby]{
IO
.write("testfile", "test")
f = File.open("testfile")
f.read # => "test"
f.close
# f.read # => IOError (すでに close しているので read できない)
//}

@see IO#closed?, IO#close_read, IO#close_write...

IO.binwrite(path, string, offset=nil) -> Integer (331.0)

path で指定されるファイルを開き、string を書き込み、 閉じます。

...書き込み、
閉じます。

ファイルを開くときの mode が "rb:ASCII-8BIT" で、バイナリモードが有効
である点以外は IO.write と同じです。

Kernel.#open と同様 path の先頭が "|" ならば、"|" に続くコマンドを実行し、コマンドの出力を...
...89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52

# binwriteを使用した場合: どの環境でも正しく保存できる。
IO
.binwrite('white.binmode.png', png)
puts IO.binread('white.binmode.png', 16).unpack('C*').map {|c| '%02x' % c }.join(' ')
# => 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 4...
...
IO
.write('white.txtmode.png', png)
puts IO.binread('white.txtmode.png', 16).unpack('C*').map {|c| '%02x' % c }.join(' ')
# => 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 (Linux/Macの場合
# => 89 50 4e 47 0d 0d 0a 1a 0d 0a 00 00 00 0d 49 48 (Windowsの場合
//}

@see c:IO#io_binmode, IO.w...

IO.for_fd(fd, mode = "r", **opts) -> IO (124.0)

オープン済みのファイルディスクリプタ fd に対する新しい IO オブジェクトを生成して返します。

...オープン済みのファイルディスクリプタ fd に対する新しい
IO
オブジェクトを生成して返します。

IO
.open にブロックが与えられた場合、IO オブジェクトを生成しそれを引数としてブロックを
実行します。ブロックの終了と...
...ともに fd はクローズされます。ブロックの結果を返します。
IO
.new, IO.for_fd はブロックを受け付けません。

=== キーワード引数
このメソッドは以下のキーワード引数を利用できます。
* :mode mode引数と同じ意味です
* :extern...
...用いられます。


@param fd ファイルディスクリプタである整数を指定します。

@param mode Kernel.#open と同じ形式で IO のモードを指定します。File::Constants::RDONLY などの
定数(数値)でモードを指定できます。詳細は組み込...

IO.new(fd, mode = "r", **opts) -> IO (124.0)

オープン済みのファイルディスクリプタ fd に対する新しい IO オブジェクトを生成して返します。

...オープン済みのファイルディスクリプタ fd に対する新しい
IO
オブジェクトを生成して返します。

IO
.open にブロックが与えられた場合、IO オブジェクトを生成しそれを引数としてブロックを
実行します。ブロックの終了と...
...ともに fd はクローズされます。ブロックの結果を返します。
IO
.new, IO.for_fd はブロックを受け付けません。

=== キーワード引数
このメソッドは以下のキーワード引数を利用できます。
* :mode mode引数と同じ意味です
* :extern...
...用いられます。


@param fd ファイルディスクリプタである整数を指定します。

@param mode Kernel.#open と同じ形式で IO のモードを指定します。File::Constants::RDONLY などの
定数(数値)でモードを指定できます。詳細は組み込...

絞り込み条件を変える

IO#readlines(limit, chomp: false) -> [String] (118.0)

データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。

...@param chomp true を指定すると各行の末尾から rs を取り除きます。

@raise IOError 自身が読み込み用にオープンされていなければ発生します。

//emlist[例][ruby]{
IO
.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines }...
...chomp = true)][ruby]{
IO
.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # => ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\nline3,\n"]
//}

@see $/, IO#gets...

IO#readlines(rs = $/, chomp: false) -> [String] (118.0)

データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。

...@param chomp true を指定すると各行の末尾から rs を取り除きます。

@raise IOError 自身が読み込み用にオープンされていなければ発生します。

//emlist[例][ruby]{
IO
.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines }...
...chomp = true)][ruby]{
IO
.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # => ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\nline3,\n"]
//}

@see $/, IO#gets...

IO#readlines(rs, limit, chomp: false) -> [String] (118.0)

データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。

...@param chomp true を指定すると各行の末尾から rs を取り除きます。

@raise IOError 自身が読み込み用にオープンされていなければ発生します。

//emlist[例][ruby]{
IO
.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines }...
...chomp = true)][ruby]{
IO
.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # => ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\nline3,\n"]
//}

@see $/, IO#gets...

IO.foreach(path, rs = $/, chomp: false) -> Enumerator (115.0)

path で指定されたファイルの各行を引数としてブロックを繰り返し実行します。 path のオープンに成功すれば nil を返します。

...][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.foreach("testfile") # => #<Enumerator: IO:foreach("testfile")>
IO
.foreach("testfile") { |x| print "GOT ", x }
# => GOT line1
# GOT line2,
# GOT line3
//}

//emlist[例:カンマを行の区切りに指定( rs = "," )][ruby]{
IO
.write("t...
...", "line1,line2,line3")
IO
.foreach("testfile", ",") { |x| puts "GOT #{x}" }
# => GOT line1,
# GOT line2,
# GOT line3
//}

//emlist[例: 各行の末尾から "\n", "\r", または "\r\n" を取り除く(chomp = true)][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.foreach("testfile", c...

IO#sysread(maxlen, outbuf = "") -> String (64.0)

read(2) を用いて入力を行ない、入力されたデータを 含む文字列を返します。stdio を経由しないので gets や getc や eof? などと混用すると思わぬ動作 をすることがあります。

...read(2) を用いて入力を行ない、入力されたデータを
含む文字列を返します。stdio を経由しないので gets や getc や eof? などと混用すると思わぬ動作
をすることがあります。

バイナリ読み込みメソッドとして動作します。

...
...します。

@param maxlen 入力のサイズを整数で指定します。

@param outbuf 出力用のバッファを文字列で指定します。IO#sysread は読み込んだデータを
その文字列オブジェクトに上書きして返します。指定した文字列オブ...
...小)されたあと、実際に読み込んだデータのサイズになります。

@raise IOError 自身が読み込み用にオープンされていなければ発生します。

@raise EOFError IO が既に EOF に達していれば発生します。

@raise Errno::EXXX データの読み込...

絞り込み条件を変える

IO.readlines(path, limit, chomp: false, opts={}) -> [String] (64.0)

path で指定されたファイルを全て読み込んで、その各行を要素としてもつ配列を返します。

...emlist[例][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.readlines("testfile") # => ["line1\n", "line2,\n", "line3\n"]
IO
.readlines("testfile", ",") # => ["line1\nline2,", "\nline3\n"]
//}

//emlist[例: rs を取り除く(chomp = true)][ruby]{
IO
.write("testfile",...
..."line1,\rline2,\r\nline3,\n")
IO
.readlines("testfile", chomp: true) # => ["line1,\rline2,", "line3,"]
IO
.readlines("testfile", "\r", chomp: true) # => ["line1,", "line2,", "\nline3,\n"]
//}...

IO.readlines(path, rs = $/, chomp: false, opts={}) -> [String] (64.0)

path で指定されたファイルを全て読み込んで、その各行を要素としてもつ配列を返します。

...emlist[例][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.readlines("testfile") # => ["line1\n", "line2,\n", "line3\n"]
IO
.readlines("testfile", ",") # => ["line1\nline2,", "\nline3\n"]
//}

//emlist[例: rs を取り除く(chomp = true)][ruby]{
IO
.write("testfile",...
..."line1,\rline2,\r\nline3,\n")
IO
.readlines("testfile", chomp: true) # => ["line1,\rline2,", "line3,"]
IO
.readlines("testfile", "\r", chomp: true) # => ["line1,", "line2,", "\nline3,\n"]
//}...

IO.readlines(path, rs, limit, chomp: false, opts={}) -> [String] (64.0)

path で指定されたファイルを全て読み込んで、その各行を要素としてもつ配列を返します。

...emlist[例][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.readlines("testfile") # => ["line1\n", "line2,\n", "line3\n"]
IO
.readlines("testfile", ",") # => ["line1\nline2,", "\nline3\n"]
//}

//emlist[例: rs を取り除く(chomp = true)][ruby]{
IO
.write("testfile",...
..."line1,\rline2,\r\nline3,\n")
IO
.readlines("testfile", chomp: true) # => ["line1,\rline2,", "line3,"]
IO
.readlines("testfile", "\r", chomp: true) # => ["line1,", "line2,", "\nline3,\n"]
//}...

IO.write(path, string, **opts) -> Integer (49.0)

path で指定されるファイルを開き、string を書き込み、 閉じます。

...キーワード引数はファイルを開くときに使われ、エンコーディングなどを指定することができます。
詳しくは IO.open を見てください。

@param path ファイル名文字列
@param string 書き込む文字列
@param offset 書き込み開始位置
@par...
...s line three\nAnd so on...\n"
IO
.write("testfile", text) # => 66
IO
.write("testfile", "0123456789", 20) #=> 10
IO
.read("testfile")
# => "This is line one\nThi0123456789two\nThis is line three\nAnd so on...\n"
IO
.write("testfile", "0123456789") #=> 10
IO
.read("testfile")...
...# => "0123456789"
//}

@see IO.binwrite...

IO#clone -> IO (46.0)

レシーバと同じ IO を参照する新しい IO オブジェクトを返します。 参照しているファイル記述子は dup(2) されます。

...シーバと同じ IO を参照する新しい IO オブジェクトを返します。
参照しているファイル記述子は dup(2) されます。

clone の際に self は一旦 IO#flush されます。
フリーズした IO の clone は同様にフリーズされた IO を返しますが、...
...しいフリーズされていない IO を返します。

@raise IOError 既に close されていた場合に発生します。

//emlist[例][ruby]{
clone_io = nil
IO
.write("testfile", "test")
File.open("testfile") do |io|
clone_io = io.clone
end
clone_io.read # => "test"
clone_io.close
//}...

絞り込み条件を変える

IO#dup -> IO (46.0)

レシーバと同じ IO を参照する新しい IO オブジェクトを返します。 参照しているファイル記述子は dup(2) されます。

...シーバと同じ IO を参照する新しい IO オブジェクトを返します。
参照しているファイル記述子は dup(2) されます。

clone の際に self は一旦 IO#flush されます。
フリーズした IO の clone は同様にフリーズされた IO を返しますが、...
...しいフリーズされていない IO を返します。

@raise IOError 既に close されていた場合に発生します。

//emlist[例][ruby]{
clone_io = nil
IO
.write("testfile", "test")
File.open("testfile") do |io|
clone_io = io.clone
end
clone_io.read # => "test"
clone_io.close
//}...

IO#fcntl(cmd, arg = 0) -> Integer (46.0)

IOに対してシステムコール fcntl を実行します。 機能の詳細は fcntl(2) を参照してください。 fcntl(2) が返した整数を返します。

...
IO
に対してシステムコール fcntl を実行します。
機能の詳細は fcntl(2) を参照してください。
fcntl(2) が返した整数を返します。

@param cmd IO に対するコマンドを、添付ライブラリ fcntl が提供している定数で指定します。

@param...
...ます。

@raise Errno::EXXX fcntl の実行に失敗した場合に発生します。

@raise IOError 既に close されている場合に発生します。

//emlist[例][ruby]{
require "fcntl"

IO
.write("testfile", "abcde")
# ファイル状態フラグを読み出す
File.open("testfile") do |...