From 81d90d81d0ee1fc1a649ab705119a71f2d04c8a2 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 22 Mar 2021 10:49:18 +0900 Subject: [PATCH] Allow both `current_page?(url_hash)` and `current_page?(**url_hash)` on Ruby 2.7 Keyword argument warnings are caused by #41206 to allow both `current_page?(url_hash)` and `current_page?(**url_hash)` on Ruby 3.0. Unfortunately it is super hard to support that for both Ruby 2.7 and 3.0 with the same method signature. Closes #41710. --- actionview/lib/action_view/helpers/url_helper.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 6baeba1fbf..0faf51b100 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -577,6 +577,19 @@ module ActionView end end + if RUBY_VERSION.start_with?("2.7") + using Module.new { + refine UrlHelper do + alias :_current_page? :current_page? + end + } + + def current_page?(*args) # :nodoc: + options = args.pop + options.is_a?(Hash) ? _current_page?(*args, **options) : _current_page?(*args, options) + end + end + # Creates an SMS anchor link tag to the specified +phone_number+. When the # link is clicked, the default SMS messaging app is opened ready to send a # message to the linked phone number. If the +body+ option is specified,