Skip to content

Commit

Permalink
Fix crash in dynamic module_function within a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Feb 10, 2024
1 parent 2fcd7c9 commit f0c27ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ripper-tags/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def on_method_add_arg(call, args)
method_name = args[1][1]
end

[procedure, klass, method_name, access, line]
[procedure, klass, method_name, access, line] if method_name
when "scope", "named_scope"
scope_name = args[1][0]
[:rails_def, :scope, scope_name, line] if scope_name
Expand Down
11 changes: 11 additions & 0 deletions test/test_ripper_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ def def() end
assert_equal('method', module_tags.find{ |t| t[:name] == 'def' }[:kind])
end

def test_dynamic_module_function
tags = extract(<<-RUBY)
module Airbrussh
ANSI_CODES.each do |name, code|
module_function(name)
end
end
RUBY
assert_equal ["Airbrussh"], tags.map { |t| t.fetch(:name) }
end

def test_extract_one_line_definition_access_by_symbol
%w(private public protected).each do |visibility|
tags = extract(<<-EOC)
Expand Down

0 comments on commit f0c27ab

Please sign in to comment.