Ruby 1.9.3 リファレンスマニュアル > ライブラリ一覧 > cgi/coreライブラリ > CGIクラス > out

instance method CGI#out

out(options = "text/html") { .... }

HTTP ヘッダと、ブロックで与えられた文字列を標準出力に出力します。

HEADリクエスト (REQUEST_METHOD == "HEAD") の場合は HTTP ヘッダのみを出力します。

charset が "iso-2022-jp"・"euc-jp"・"shift_jis" のいずれかで ある場合は文字列エンコーディングを自動変換し、language を "ja"にします。

[PARAM] options:
Hash か文字列で HTTP ヘッダを生成するための情報を指定します。

例:

cgi = CGI.new
cgi.out{ "string" }
  # Content-Type: text/html
  # Content-Length: 6
  #
  # string

cgi.out("text/plain"){ "string" }
  # Content-Type: text/plain
  # Content-Length: 6
  #
  # string

cgi.out({"nph"        => true,
         "status"     => "OK",  # == "200 OK"
         "server"     => ENV['SERVER_SOFTWARE'],
         "connection" => "close",
         "type"       => "text/html",
         "charset"    => "iso-2022-jp",
           # Content-Type: text/html; charset=iso-2022-jp
         "language"   => "ja",
         "expires"    => Time.now + (3600 * 24 * 30),
         "cookie"     => [cookie1, cookie2],
         "my_header1" => "my_value",
         "my_header2" => "my_value"}){ "string" }

[SEE_ALSO] CGI#header

class CGI