44件ヒット
[1-44件を表示]
(0.044秒)
別のキーワード
検索結果
先頭4件
-
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 はグローバルスコープです。...