From 5a9afbf00a92524daf77af9d0e263fc7c403422b Mon Sep 17 00:00:00 2001 From: rm155 Date: Mon, 12 Jul 2021 16:19:01 -0400 Subject: [PATCH] Improve Ractor-compliance --- lib/uri/ftp.rb | 3 ++- lib/uri/ldap.rb | 3 ++- lib/uri/rfc2396_parser.rb | 25 ++++++++++++------------- lib/uri/rfc3986_parser.rb | 7 +++---- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/uri/ftp.rb b/lib/uri/ftp.rb index 1c75e24..aa7ab04 100644 --- a/lib/uri/ftp.rb +++ b/lib/uri/ftp.rb @@ -39,7 +39,8 @@ class FTP < Generic # * "i" indicates a binary file (FTP command IMAGE) # * "d" indicates the contents of a directory should be displayed # - TYPECODE = ['a', 'i', 'd'].freeze + TYPECODE = ['a', 'i', 'd'] + Ractor.make_shareable(TYPECODE) # Typecode prefix ";type=". TYPECODE_PREFIX = ';type='.freeze diff --git a/lib/uri/ldap.rb b/lib/uri/ldap.rb index 4544349..7974cb5 100644 --- a/lib/uri/ldap.rb +++ b/lib/uri/ldap.rb @@ -47,7 +47,8 @@ class LDAP < Generic SCOPE_ONE = 'one', SCOPE_SUB = 'sub', SCOPE_BASE = 'base', - ].freeze + ] + Ractor.make_shareable(SCOPE) if defined?(Ractor) # # == Description diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index 00c66cf..06e9797 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -25,31 +25,31 @@ module PATTERN # RFC 2373 (IPv6 Addressing Architecture) # alpha = lowalpha | upalpha - ALPHA = "a-zA-Z" + ALPHA = "a-zA-Z".freeze # alphanum = alpha | digit - ALNUM = "#{ALPHA}\\d" + ALNUM = "#{ALPHA}\\d".freeze # hex = digit | "A" | "B" | "C" | "D" | "E" | "F" | # "a" | "b" | "c" | "d" | "e" | "f" - HEX = "a-fA-F\\d" + HEX = "a-fA-F\\d".freeze # escaped = "%" hex hex - ESCAPED = "%[#{HEX}]{2}" + ESCAPED = "%[#{HEX}]{2}".freeze # mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | # "(" | ")" # unreserved = alphanum | mark - UNRESERVED = "\\-_.!~*'()#{ALNUM}" + UNRESERVED = "\\-_.!~*'()#{ALNUM}".freeze # reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | # "$" | "," # reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | # "$" | "," | "[" | "]" (RFC 2732) - RESERVED = ";/?:@&=+$,\\[\\]" + RESERVED = ";/?:@&=+$,\\[\\]".freeze # domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum - DOMLABEL = "(?:[#{ALNUM}](?:[-#{ALNUM}]*[#{ALNUM}])?)" + DOMLABEL = "(?:[#{ALNUM}](?:[-#{ALNUM}]*[#{ALNUM}])?)".freeze # toplabel = alpha | alpha *( alphanum | "-" ) alphanum - TOPLABEL = "(?:[#{ALPHA}](?:[-#{ALNUM}]*[#{ALNUM}])?)" + TOPLABEL = "(?:[#{ALPHA}](?:[-#{ALNUM}]*[#{ALNUM}])?)".freeze # hostname = *( domainlabel "." ) toplabel [ "." ] - HOSTNAME = "(?:#{DOMLABEL}\\.)*#{TOPLABEL}\\.?" + HOSTNAME = "(?:#{DOMLABEL}\\.)*#{TOPLABEL}\\.?".freeze # :startdoc: end # PATTERN @@ -321,14 +321,13 @@ def unescape(str, escaped = @regexp[:ESCAPED]) str.gsub(escaped) { [$&[1, 2]].pack('H2').force_encoding(enc) } end - @@to_s = Kernel.instance_method(:to_s) - if @@to_s.respond_to?(:bind_call) + if UnboundMethod.method_defined?(:bind_call) def inspect - @@to_s.bind_call(self) + Kernel.instance_method(:to_s).bind_call(self) end else def inspect - @@to_s.bind(self).call + Kernel.instance_method(:to_s).bind(self).call end end diff --git a/lib/uri/rfc3986_parser.rb b/lib/uri/rfc3986_parser.rb index 092a1ac..518dbc3 100644 --- a/lib/uri/rfc3986_parser.rb +++ b/lib/uri/rfc3986_parser.rb @@ -141,14 +141,13 @@ def join(*uris) # :nodoc: uris.inject :merge end - @@to_s = Kernel.instance_method(:to_s) - if @@to_s.respond_to?(:bind_call) + if UnboundMethod.method_defined?(:bind_call) def inspect - @@to_s.bind_call(self) + Kernel.instance_method(:to_s).bind_call(self) end else def inspect - @@to_s.bind(self).call + Kernel.instance_method(:to_s).bind(self).call end end