mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Use String.try_convert if available.
This commit is contained in:
parent
dd3ca9a0f1
commit
39d6965ed9
1 changed files with 18 additions and 2 deletions
|
|
@ -19,6 +19,23 @@ class HTTP::Cookie
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if String.respond_to?(:try_convert)
|
||||||
|
def check_string_type(object)
|
||||||
|
String.try_convert(object)
|
||||||
|
end
|
||||||
|
private :check_string_type
|
||||||
|
else
|
||||||
|
def check_string_type(object)
|
||||||
|
if object.is_a?(String) ||
|
||||||
|
(object.respond_to?(:to_str) && (object = object.to_str).is_a?(String))
|
||||||
|
object
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
private :check_string_type
|
||||||
|
end
|
||||||
|
|
||||||
include URIFix if defined?(URIFix)
|
include URIFix if defined?(URIFix)
|
||||||
|
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
@ -203,8 +220,7 @@ class HTTP::Cookie
|
||||||
if DomainName === domain
|
if DomainName === domain
|
||||||
@domain_name = domain
|
@domain_name = domain
|
||||||
else
|
else
|
||||||
domain.is_a?(String) or
|
domain = check_string_type(domain) or
|
||||||
(domain.respond_to?(:to_str) && (domain = domain.to_str).is_a?(String)) or
|
|
||||||
raise TypeError, "#{domain.class} is not a String"
|
raise TypeError, "#{domain.class} is not a String"
|
||||||
if domain.start_with?('.')
|
if domain.start_with?('.')
|
||||||
@for_domain = true
|
@for_domain = true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue