From 67ca99ca87a3e5f28b0f57f68d07128d5f3fb882 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 4 Mar 2021 15:19:25 -0800 Subject: [PATCH] Only use UnboundMethod#bind_call if it is available This allows tests to pass on Ruby 2.4-2.6. Fixes #19 --- lib/uri/rfc2396_parser.rb | 10 ++++++++-- lib/uri/rfc3986_parser.rb | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index c719aa0..eef31e0 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -322,8 +322,14 @@ def unescape(str, escaped = @regexp[:ESCAPED]) end @@to_s = Kernel.instance_method(:to_s) - def inspect - @@to_s.bind_call(self) + if @@to_s.respond_to?(:bind_call) + def inspect + @@to_s.bind_call(self) + end + else + def inspect + @@to_s.bind(self).call + end end private diff --git a/lib/uri/rfc3986_parser.rb b/lib/uri/rfc3986_parser.rb index 49a594c..3e07de4 100644 --- a/lib/uri/rfc3986_parser.rb +++ b/lib/uri/rfc3986_parser.rb @@ -79,8 +79,14 @@ def join(*uris) # :nodoc: end @@to_s = Kernel.instance_method(:to_s) - def inspect - @@to_s.bind_call(self) + if @@to_s.respond_to?(:bind_call) + def inspect + @@to_s.bind_call(self) + end + else + def inspect + @@to_s.bind(self).call + end end private