out() in Ruby

By: Jeeva Emailed: 1743 times Printed: 2432 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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

Print an HTTP header and body to $DEFAULT_OUTPUT ($>)

The header is provided by options, as for header(). The body of the document is that returned by the passed- in block. This block takes no arguments. It is required.

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

Content-Length is automatically calculated from the size of the String returned by the content block.

If ENV[‘REQUEST_METHOD’] == "HEAD", then only the header is outputted (the content block is still required, but it is ignored).

If the charset is "iso-2022-jp" or "euc-jp" or "shift_jis" then the content is converted to this charset, and the language is set to "ja".


Ruby Home | All Ruby Tutorials | Latest Ruby Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Jeeva
out() in Ruby
header() in Ruby
unescapeHTML() in Ruby
unescapeElement() in Ruby
URL decode a string in Ruby
Format a Time object as a String in Ruby
pretty() in Ruby
parse(query) in Ruby
new(type = "query") in Ruby
escapeHTML() in Ruby
escapeElement() in Ruby
URL encode a string in Ruby
CGI class in Ruby

More Tutorials in Ruby
Standard Library Packages in Ruby
Module Abbrev in Ruby
encoding and decoding in Ruby using Base64 Module
Benchmark module in Ruby
benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) {|report| ...} in Ruby
bm(label_width = 0, *labels) {|report| ...} in Ruby
bmbm(width = 0) {|job| ...} in Ruby
CGI class in Ruby
URL encode a string in Ruby
escapeElement() in Ruby
escapeHTML() in Ruby
new(type = "query") in Ruby
parse(query) in Ruby
pretty() in Ruby
Format a Time object as a String in Ruby

More Latest News
Most Viewed Articles (in Ruby )
encoding and decoding in Ruby using Base64 Module
if . . . elsif . . . else in Ruby on rails
Using Proxy to connect to URLs in Ruby
Open and manipulate CSV files in Ruby
Reading emails using POP3 in Ruby
Defining tables and classes (using MySQL) in Ruby on Rails
Module Abbrev in Ruby
Benchmark module in Ruby
new(type = "query") in Ruby
URL decode a string in Ruby
Reading URL content using Ruby (HTTP)
Sending emails using SMTP in Ruby
Command-line Arguments in Ruby on rails
Methods in Ruby on rails
Standard Library Packages in Ruby
Most Emailed Articles (in Ruby)
if . . . elsif . . . else in Ruby on rails
Sending emails using SMTP in Ruby
encoding and decoding in Ruby using Base64 Module
bmbm(width = 0) {|job| ...} in Ruby
escapeHTML() in Ruby
Format a Time object as a String in Ruby
benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) {|report| ...} in Ruby
bm(label_width = 0, *labels) {|report| ...} in Ruby
dRuby client/server mode sample program
Using Proxy to connect to URLs in Ruby
Using Observer in Ruby
Getting started with Ruby on rails
Prompts, Command Lines, Prompts, and irb in Ruby on rails
CGI class in Ruby
URL encode a string in Ruby