Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parse error for delegate statements with dynamic arguments #114

Merged
merged 4 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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