Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • cgi/core.rb


Mixin module. It provides the follow functionality groups:

  1. Access to CGI environment variables as methods. See documentation to the CGI class for a list of these variables.

  2. Access to cookies, including the cookies attribute.

  3. Access to parameters, including the params attribute, and overloading

    to perform parameter value lookup by key.

  4. The initialize_query method, for initialising the above mechanisms, handling multipart forms, and allowing the class to be used in “offline” mode.



Get the cookies as a hash of cookie-name=>Cookie pairs.


Get the uploaded files as a hash of name=>values pairs


Get the parameters as a hash of name=>values pairs, where values is an Array.

Public Instance Methods

[](key) click to toggle source

Get the value for the parameter with a given key.

If the parameter has multiple values, only the first will be retrieved; use params() to get the array of values.

               # File cgi/core.rb, line 627
def [](key)
  params = @params[key]
  return '' unless params
  value = params[0]
  if @multipart
    if value
      return value
    elsif defined? StringIO
    str = if value then value.dup else "" end
has_key?(*args) click to toggle source

Returns true if a given parameter key exists in the query.

               # File cgi/core.rb, line 651
def has_key?(*args)
Also aliased as: key?, include?
include?(*args) click to toggle source
Alias for: has_key?
key?(*args) click to toggle source
Alias for: has_key?
keys(*args) click to toggle source

Return all parameter keys as an array.

               # File cgi/core.rb, line 646
def keys(*args)
multipart?() click to toggle source
               # File cgi/core.rb, line 619
def multipart?
params=(hash) click to toggle source

Set all the parameters.

               # File cgi/core.rb, line 409
def params=(hash)
raw_cookie2() click to toggle source

Get the raw RFC2965 cookies as a string.

               # File cgi/core.rb, line 394
def raw_cookie2

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.