るりまサーチ

最速Rubyリファレンスマニュアル検索!
44件ヒット [1-44件を表示] (0.047秒)
トップページ > クエリ:_builtin[x] > クエリ:new[x] > クエリ:reopen[x]

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

クラス

モジュール

検索結果

IO#reopen(path) -> self (26121.0)

path で指定されたファイルにストリームを繋ぎ換えます。

..."testfile", "This is line one\nThis is line two\n")
f1 = File.new("testfile", "a+")
f2 = File.new("testfile")
f1.print("This is line three\n")
f2.readlines # => ["This is line one\n", "This is line two\n"]
f1.close
f2.reopen("testfile", "r") # => #<File:testfile>
f2.readlines...

IO#reopen(path, mode) -> self (26121.0)

path で指定されたファイルにストリームを繋ぎ換えます。

..."testfile", "This is line one\nThis is line two\n")
f1 = File.new("testfile", "a+")
f2 = File.new("testfile")
f1.print("This is line three\n")
f2.readlines # => ["This is line one\n", "This is line two\n"]
f1.close
f2.reopen("testfile", "r") # => #<File:testfile>
f2.readlines...

IO#reopen(io) -> self (26106.0)

自身を指定された io に繋ぎ換えます。

自身を指定された io に繋ぎ換えます。

クラスも io に等しくなることに注意してください。
IO#pos, IO#lineno などは指定された io と等しくなります。

@param io 自身を繋ぎ換えたい IO オブジェクトを指定します。

@raise IOError 指定された io が close されている場合に発生します。

Kernel$$stdin -> object (8030.0)

標準入力です。

...例][ruby]{
$stdin = Object.new
def $stdin.gets
"foo"
end
p gets() # => "foo"
//}

自プロセスだけでなく、子プロセスの標準入力もリダイレクトしたいときは
以下のように IO#reopen を使います。

//emlist[例][ruby]{
$stdin.reopen("/tmp/foo")
//}

また、...
...[例][ruby]{
stdin_old = $stdin.dup # 元の $stdin を保存する
$stdout.reopen("/tmp/foo") # $stdin を /tmp/foo にリダイレクトする
gets # /tmp/foo から入力
$stdin.reopen stdin_old # 元に戻す
//}

$stdin はグローバルスコープです...