るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.017秒)
トップページ > クエリ:tell[x] > クエリ:seek[x] > クエリ:open[x] > 種類:変数[x]

別のキーワード

  1. _builtin tell
  2. csv tell
  3. zlib tell
  4. stringio tell
  5. dir tell

ライブラリ

モジュール

検索結果

Kernel$$stdin -> object (19.0)

標準入力です。

...クトしたいときは
$stdin に代入すれば十分です。

//emlist[例][ruby]{
# 標準入力の入力元 /tmp/foo に変更
$stdin = File.open("/tmp/foo", "r")
gets # 入力する
$stdin = STDIN # 元に戻す
//}

ただし、Kernel.#gets など、特定の組み込み...
...ブジェクトが以下のメソッドを
正しく実装していなければいけません。

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
"...
...IO#reopen を使います。

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

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

//emlist[例][ruby]{
stdin_old = $stdin.dup # 元の $stdin を保存する
$stdout.reopen("/tm...