[前][次][番号順一覧][スレッド一覧]

ruby-changes:28311

From: xibbar <ko1@a...>
Date: Fri, 19 Apr 2013 08:47:16 +0900 (JST)
Subject: [ruby-changes:28311] xibbar:r40363 (trunk): * lib/cgi/cookie.rb: refactoring.

xibbar	2013-04-19 08:47:07 +0900 (Fri, 19 Apr 2013)

  New Revision: 40363

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40363

  Log:
    * lib/cgi/cookie.rb: refactoring.

  Modified files:
    trunk/lib/cgi/cookie.rb

Index: lib/cgi/cookie.rb
===================================================================
--- lib/cgi/cookie.rb	(revision 40362)
+++ lib/cgi/cookie.rb	(revision 40363)
@@ -1,6 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/lib/cgi/cookie.rb#L1
 require 'cgi/util'
 class CGI
-  @@accept_charset="UTF-8" unless defined?(@@accept_charset)
   # Class representing an HTTP cookie.
   #
   # In addition to its specific fields and methods, a Cookie instance
@@ -9,9 +8,9 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/cookie.rb#L8
   # See RFC 2965.
   #
   # == Examples of use
-  #   cookie1 = CGI::Cookie::new("name", "value1", "value2", ...)
-  #   cookie1 = CGI::Cookie::new("name" => "name", "value" => "value")
-  #   cookie1 = CGI::Cookie::new('name'    => 'name',
+  #   cookie1 = CGI::Cookie.new("name", "value1", "value2", ...)
+  #   cookie1 = CGI::Cookie.new("name" => "name", "value" => "value")
+  #   cookie1 = CGI::Cookie.new('name'    => 'name',
   #                              'value'   => ['value1', 'value2', ...],
   #                              'path'    => 'path',   # optional
   #                              'domain'  => 'domain', # optional
@@ -35,6 +34,7 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/cookie.rb#L34
   #   cookie1.expires = Time.now + 30
   #   cookie1.secure  = true
   class Cookie < Array
+    @@accept_charset="UTF-8" unless defined?(@@accept_charset)
 
     # Create a new CGI::Cookie object.
     #
@@ -125,7 +125,7 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/cookie.rb#L125
 
     # Convert the Cookie to its string representation.
     def to_s
-      val = collect{|v| CGI::escape(v) }.join("&")
+      val = collect{|v| CGI.escape(v) }.join("&")
       buf = "#{@name}=#{val}"
       buf << "; domain=#{@domain}" if @domain
       buf << "; path=#{@path}"     if @path
@@ -134,32 +134,32 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/cookie.rb#L134
       buf
     end
 
-  end # class Cookie
-
-  # Parse a raw cookie string into a hash of cookie-name=>Cookie
-  # pairs.
-  #
-  #   cookies = CGI::Cookie::parse("raw_cookie_string")
-  #     # { "name1" => cookie1, "name2" => cookie2, ... }
-  #
-  def Cookie::parse(raw_cookie)
-    cookies = Hash.new([])
-    return cookies unless raw_cookie
-
-    raw_cookie.split(/[;,]\s?/).each do |pairs|
-      name, values = pairs.split('=',2)
-      next unless name and values
-      name = CGI::unescape(name)
-      values ||= ""
-      values = values.split('&').collect{|v| CGI::unescape(v,@@accept_charset) }
-      if cookies.has_key?(name)
-        values = cookies[name].value + values
+    # Parse a raw cookie string into a hash of cookie-name=>Cookie
+    # pairs.
+    #
+    #   cookies = CGI::Cookie.parse("raw_cookie_string")
+    #     # { "name1" => cookie1, "name2" => cookie2, ... }
+    #
+    def self.parse(raw_cookie)
+      cookies = Hash.new([])
+      return cookies unless raw_cookie
+
+      raw_cookie.split(/[;,]\s?/).each do |pairs|
+        name, values = pairs.split('=',2)
+        next unless name and values
+        name = CGI.unescape(name)
+        values ||= ""
+        values = values.split('&').collect{|v| CGI.unescape(v,@@accept_charset) }
+        if cookies.has_key?(name)
+          values = cookies[name].value + values
+        end
+        cookies[name] = Cookie.new(name, *values)
       end
-      cookies[name] = Cookie::new(name, *values)
+
+      cookies
     end
 
-    cookies
-  end
+  end # class Cookie
 end
 
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]