概要
様々な標準出力の書き方
詳細
「$>,$stdout」は標準出力です。
出力先はデフォルトで Object::STDOUT定数 になっています。
Object::STDOUT定数は IO のインスタンスです。
IOクラスは出力のためのインスタンスメソッド「<<」を持っているため
下記のような記述で標準出力が可能です。
$><<"message" $stdout<<"message" $STDOUT<<"message"
サンプルコード
# encoding: utf-8 system("echo 0") $><<"1\n" $stdout<<"2\n" STDOUT<<"3\n" $>.write "4\n" $stdout.write "5\n" STDOUT.write"6\n" print"7\n" puts"8" p"9" $VERBOSE = nil # 警告抑止 $>.syswrite"10\n" $stdout.syswrite"11\n" STDOUT.syswrite"12\n" putc 97 puts spawn("echo 13")
出力
0 1 2 3 4 5 6 7 8 "9" 10 11 12 a 13
参照
http://docs.ruby-lang.org/ja/2.1.0/method/Kernel/v/stdout.html
http://docs.ruby-lang.org/ja/2.1.0/method/Object/c/STDOUT.html
http://docs.ruby-lang.org/ja/2.1.0/class/IO.html#I_--3C--3C
http://docs.ruby-lang.org/ja/2.1.0/method/Kernel/m/system.html
http://docs.ruby-lang.org/ja/2.1.0/method/Kernel/m/spawn.html