Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/uri/rfc2396_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,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) # :nodoc:
if TO_S.respond_to?(:bind_call)
if UnboundMethod.method_defined?(:bind_call)
def inspect # :nodoc:
TO_S.bind_call(self)
Kernel.instance_method(:to_s).bind_call(self)
end
else
def inspect # :nodoc:
TO_S.bind(self).call
Kernel.instance_method(:to_s).bind(self).call
end
end

Expand Down
7 changes: 3 additions & 4 deletions lib/uri/rfc3986_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,13 @@ def unescape(str, escaped = nil) # :nodoc:
escaped ? RFC2396_PARSER.unescape(str, escaped) : RFC2396_PARSER.unescape(str)
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

Expand Down
5 changes: 5 additions & 0 deletions test/uri/test_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def test_ractor
assert_ractor(<<~RUBY, require: 'uri')
r = Ractor.new { URI.parse("https://ruby-lang.org/").inspect }
assert_equal(URI.parse("https://ruby-lang.org/").inspect, r.value)

r = Ractor.new { [URI::RFC3986_PARSER.inspect, URI::RFC2396_PARSER.inspect] }
rfc3986, rfc2396 = r.value
assert_match(/URI::RFC3986_Parser/, rfc3986)
assert_match(/URI::RFC2396_Parser/, rfc2396)
RUBY
end

Expand Down