Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
CGI::Cookie.new
# File tmp/rubies/ruby-3.3.0/lib/cgi/cookie.rb, line 75
def initialize(name = "", *value)
@domain = nil
@expires = nil
if name.kind_of?(String)
self.name = name
self.path = (%r|\A(.*/)| =~ ENV["SCRIPT_NAME"] ? $1 : "")
@secure = false
@httponly = false
return super(value)
end
options = name
unless options.has_key?("name")
raise ArgumentError, "`name' required"
end
self.name = options["name"]
value = Array(options["value"])
# simple support for IE
self.path = options["path"] || (%r|\A(.*/)| =~ ENV["SCRIPT_NAME"] ? $1 : "")
self.domain = options["domain"]
@expires = options["expires"]
@secure = options["secure"] == true
@httponly = options["httponly"] == true
super(value)
end
Create a new CGI::Cookie object.
name_string-
The name of the cookie; in this form, there is no
domainor expiration. Thepathis gleaned from theSCRIPT_NAMEenvironment variable, andsecureis false. *value-
value or list of values of the cookie
options_hash-
A
Hashof options to initialize thisCookie. Possible options are:- name
-
the name of the cookie. Required.
- value
-
the cookie’s value or list of values.
- path
-
the path for which this cookie applies. Defaults to the value of the
SCRIPT_NAMEenvironment variable. - domain
-
the domain for which this cookie applies.
- expires
-
the time at which this cookie expires, as a
Timeobject. - secure
-
whether this cookie is a secure cookie or not (default to false). Secure cookies are only transmitted to HTTPS servers.
- httponly
-
whether this cookie is a HttpOnly cookie or not (default to
false). HttpOnly cookies are not available to javascript.
These keywords correspond to attributes of the cookie object.