Skip to content

Commit

Permalink
Fix parse error for delegate statements with dynamic arguments (#114)
Browse files Browse the repository at this point in the history
Co-authored-by: Mislav Marohnić <[email protected]>
  • Loading branch information
latortuga and mislav authored May 30, 2023
1 parent 2200945 commit aac79d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ripper-tags/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ':'
Expand Down
3 changes: 3 additions & 0 deletions test/test_ripper_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aac79d8

Please sign in to comment.