72件ヒット
[1-72件を表示]
(0.063秒)
別のキーワード
モジュール
- Kernel (72)
検索結果
先頭5件
-
Kernel
$ $ stderr -> object (31.0) -
標準エラー出力です。
...標準エラー出力です。
Ruby インタプリタが出力するエラーメッセージや
警告メッセージ、Kernel.#warn の出力先となります。
初期値は Object::STDERR です。
$stderr に代入するオブジェクトには
write という名前のメソッドが定義......出力をリダイレクトしたいときには、
$stderr に代入すれば十分です。
//emlist[例][ruby]{
# 標準エラー出力の出力先を /tmp/foo に変更
$stderr = File.open("/tmp/foo", "w")
puts "foo" # 出力する
$stderr = STDERR # 元に戻す
//}
自プロセス......下のように IO#reopen を使います。
//emlist[例][ruby]{
$stderr.reopen("/tmp/foo", "w")
//}
また、リダイレクトしたあと
出力先をまた元に戻したい場合は以下のようにします。
//emlist[例][ruby]{
stderr_old = $stderr.dup # 元の $stderr を保存... -
Kernel
$ $ stdin -> object (31.0) -
標準入力です。
...セスの標準入力をリダイレクトしたいときは
$stdin に代入すれば十分です。
//emlist[例][ruby]{
# 標準入力の入力元 /tmp/foo に変更
$stdin = File.open("/tmp/foo", "r")
gets # 入力する
$stdin = STDIN # 元に戻す
//}
ただし、Kernel.#g......なければいけません。
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 を保存する... -
Kernel
$ $ > -> object (25.0) -
標準出力です。
...イレクトしたいときには、
以下のように $stdout に代入すれば十分です。
//emlist[例][ruby]{
# 標準出力の出力先を /tmp/foo に変更
$stdout = File.open("/tmp/foo", "w")
puts "foo" # 出力する
$stdout = STDOUT # 元に戻す
//}
自プロセスだけ......下のように IO#reopen を使います。
//emlist[例][ruby]{
STDOUT.reopen("/tmp/foo", "w")
//}
また、リダイレクトしたあと
出力先をまた元に戻したい場合は以下のようにします。
//emlist[例][ruby]{
stdout_old = $stdout.dup # 元の $stdout を保存......") # $stdout を /tmp/foo にリダイレクトする
puts "foo" # /tmp/foo に出力
$stdout.flush # 念のためフラッシュする
$stdout.reopen stdout_old # 元に戻す
//}
$stdout はグローバルスコープです。
@see spec/rubycmd... -
Kernel
$ $ stdout -> object (25.0) -
標準出力です。
...イレクトしたいときには、
以下のように $stdout に代入すれば十分です。
//emlist[例][ruby]{
# 標準出力の出力先を /tmp/foo に変更
$stdout = File.open("/tmp/foo", "w")
puts "foo" # 出力する
$stdout = STDOUT # 元に戻す
//}
自プロセスだけ......下のように IO#reopen を使います。
//emlist[例][ruby]{
STDOUT.reopen("/tmp/foo", "w")
//}
また、リダイレクトしたあと
出力先をまた元に戻したい場合は以下のようにします。
//emlist[例][ruby]{
stdout_old = $stdout.dup # 元の $stdout を保存......") # $stdout を /tmp/foo にリダイレクトする
puts "foo" # /tmp/foo に出力
$stdout.flush # 念のためフラッシュする
$stdout.reopen stdout_old # 元に戻す
//}
$stdout はグローバルスコープです。
@see spec/rubycmd... -
Kernel
$ $ INPUT _ LINE _ NUMBER -> Integer (13.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 (13.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...