るりまサーチ

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

別のキーワード

  1. io popen
  2. io pipe
  3. io readlines
  4. io each_line
  5. io each

ライブラリ

クラス

モジュール

検索結果

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

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

... io に繋ぎ換えます。

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

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

@raise IOError 指定された io が c...

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

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

...ぎます。
IO
#pos, IO#lineno などはリセットされます。

@param path パスを表す文字列を指定します。

@param mode パスを開く際のモードを文字列で指定します。

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

//emlist[例][ruby]{
IO
.write("test...
...stfile", "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 # => ["This is line one\n", "This is line two\n", "This is li...

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

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

...ぎます。
IO
#pos, IO#lineno などはリセットされます。

@param path パスを表す文字列を指定します。

@param mode パスを開く際のモードを文字列で指定します。

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

//emlist[例][ruby]{
IO
.write("test...
...stfile", "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 # => ["This is line one\n", "This is line two\n", "This is li...

Kernel$$stdin -> object (42.0)

標準入力です。

...ジェクトが以下のメソッドを
正しく実装していなければいけません。

gets, readline, readlines, getc, readchar, tell, seek,
pos=, rewind, fileno, to_io, eof, each_line, each_byte,
binmode, closed?

//emlist[例][ruby]{
$stdin = Object.new
def $stdin.gets
"foo...
... IO#reopen を使います。

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

また、リダイレクトしたあと
出力先をまた元に戻したい場合は以下のようにします。

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

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