るりまサーチ

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

別のキーワード

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

ライブラリ

キーワード

検索結果

Kernel$$DEFAULT_INPUT -> IO (108.0)

$< の別名

...$< の別名

require "English"
while line = $DEFAULT_INPUT.gets
p line
end
# end of sample.rb

ruby sample.rb < /etc/passwd
# => "hoge:x:500:501::/home/hoge:/bin/bash\n"
......

Kernel$$stdin -> object (55.0)

標準入力です。

...le.open("/tmp/foo", "r")
gets
# 入力する
$stdin = STDIN # 元に戻す
//}

ただし、Kernel.#gets など、特定の組み込みメソッドは
$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")
//}

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