るりまサーチ

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

別のキーワード

  1. _builtin to_i
  2. fiddle to_i
  3. matrix elements_to_i
  4. ipaddr to_i
  5. kernel $-i

ライブラリ

モジュール

キーワード

検索結果

Kernel$$INPUT_LINE_NUMBER -> Integer (12325.0)

$. の別名

...$. の別名

1 e
2 f
3 g
4 h
5 i
# end of a.txt

require "English"

File
.foreach(ARGV.at(0)){|line|
# read line
}
p $INPUT_LINE_NUMBER
# end of sample.rb

ruby sample.rb a.txt
#=> 5...

Kernel$$NR -> Integer (6125.0)

$. の別名

...$. の別名

1 e
2 f
3 g
4 h
5 i
# end of a.txt

require "English"

File
.foreach(ARGV.at(0)){|line|
# read line
}
p $INPUT_LINE_NUMBER
# end of sample.rb

ruby sample.rb a.txt
#=> 5...

Kernel$$stdin -> object (6113.0)

標準入力です。

...$stdin に代入すれば十分です。

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

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

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")
//}

また、リ...