From a75a2894cea699cf6b1894220daa9793d4f7694d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 19 Sep 2021 16:11:17 +0200 Subject: [PATCH] Make link_list compatible with Ruby 3 keyword args We were using an optional parameter followed by keyword parameters, which caused a warning with Ruby 2.7: ``` app/components/shared/link_list_component.rb:20: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call ``` I've tried to make `current:` a named parameter as well and then change all method calls to `link_list`, but was still getting the same warning. Might have something to do with the fact that we're dealing with arrays with hashes inside them instead of passing the keyword arguments directly to the method. --- app/components/shared/link_list_component.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/components/shared/link_list_component.rb b/app/components/shared/link_list_component.rb index 3a9a21b68..ccfc97b69 100644 --- a/app/components/shared/link_list_component.rb +++ b/app/components/shared/link_list_component.rb @@ -17,7 +17,15 @@ class Shared::LinkListComponent < ApplicationComponent end def list_items - present_links.map do |text, url, current = false, **link_options| + present_links.map do |text, url, current_or_options = false, options = {}| + if current_or_options.is_a?(Hash) + current = false + link_options = current_or_options + else + current = current_or_options + link_options = options + end + tag.li("aria-current": (true if current)) do if url link_to text, url, link_options