るりまサーチ

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

別のキーワード

  1. openssl new
  2. _builtin new
  3. rexml/document new
  4. resolv new
  5. socket new

モジュール

検索結果

Kernel$$stdin -> object (20.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
"foo"
end
p gets() # => "foo"
//}

自プロセスだ...
...IO#reopen を使います。

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

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

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