From 236f3af7194f0ba3d9baa1e575c2ca197187c99c Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Fri, 15 Mar 2013 12:08:45 +0900 Subject: [PATCH] Extend URI() globally. URI() is like everywhere by now. --- lib/http/cookie.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/http/cookie.rb b/lib/http/cookie.rb index a8c1e87..45b7917 100644 --- a/lib/http/cookie.rb +++ b/lib/http/cookie.rb @@ -7,6 +7,17 @@ module HTTP autoload :CookieJar, 'http/cookie_jar' end +# In Ruby < 1.9.3 URI() does not accept an URI object. +if RUBY_VERSION < "1.9.3" + begin + URI(URI('')) + rescue + def URI(url) + url.is_a?(URI) ? url : URI.parse(url) + end + end +end + # This class is used to represent an HTTP Cookie. class HTTP::Cookie # Maximum number of bytes per cookie (RFC 6265 6.1 requires 4096 at least) @@ -25,16 +36,6 @@ class HTTP::Cookie expires created_at accessed_at ] - # In Ruby < 1.9.3 URI() does not accept an URI object. - if RUBY_VERSION < "1.9.3" - module URIFix - def URI(url) - url.is_a?(URI) ? url : Kernel::URI(url) - end - private :URI - end - end - if String.respond_to?(:try_convert) def check_string_type(object) String.try_convert(object) @@ -52,8 +53,6 @@ class HTTP::Cookie private :check_string_type end - include URIFix if defined?(URIFix) - attr_reader :name, :domain, :path, :origin attr_accessor :secure, :httponly, :value, :version attr_reader :domain_name, :expires