From aac79d871f5dea0bf1852d9fe0e3d2af63211635 Mon Sep 17 00:00:00 2001 From: Drew Ulmer Date: Tue, 30 May 2023 11:40:51 -0500 Subject: [PATCH] Fix parse error for delegate statements with dynamic arguments (#114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mislav Marohnić --- lib/ripper-tags/parser.rb | 4 ++-- test/test_ripper_tags.rb | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ripper-tags/parser.rb b/lib/ripper-tags/parser.rb index d463bb3..505d355 100644 --- a/lib/ripper-tags/parser.rb +++ b/lib/ripper-tags/parser.rb @@ -316,8 +316,8 @@ def on_assoc_new(key, value) end def on_delegate(*args) - method_names = args.select { |arg| arg.first.is_a? String } - options = args.select { |arg| arg.first.is_a?(Array) && arg.first.first == :assoc }.flatten(1) + method_names = args.select { |arg| arg.is_a?(Array) && arg.first.is_a?(String) } + options = args.select { |arg| arg.is_a?(Array) && arg.first.is_a?(Array) && arg.first.first == :assoc }.flatten(1) options = Hash[options.map { |_assoc, key, val| [key[0], val[0]] if key }.compact] target = options["to:"] || options["to"] # When using hashrocket syntax there is no ':' diff --git a/test/test_ripper_tags.rb b/test/test_ripper_tags.rb index 3ab26de..a4efff7 100644 --- a/test/test_ripper_tags.rb +++ b/test/test_ripper_tags.rb @@ -578,6 +578,9 @@ def test_invalid_delegate class C delegate delegate [1, 2] + [:test].each do |m| + delegate m, :"\#{m}=", :to => :object + end end EOC assert_equal 1, tags.count