Skip to content

Commit 242a1e9

Browse files
committed
Refactor Parser::Ruby#call_node_name_arguments
Arguably, these methods belong more to the visitor than the "scanner". Since they simply process prism nodes without any ivar references, they should probably be converted into module functions on a utility module.
1 parent a7f4df8 commit 242a1e9

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

‎lib/rdoc/parser/ruby.rb‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,23 @@ def handle_modifier_directive(code_object, line_no) # :nodoc:
389389
end
390390

391391
def call_node_name_arguments(call_node) # :nodoc:
392-
return [] unless call_node.arguments
393-
call_node.arguments.arguments.map do |arg|
394-
case arg
395-
when Prism::SymbolNode
396-
arg.value
397-
when Prism::StringNode
398-
arg.unescaped
399-
end
400-
end || []
392+
return unless arguments_node = call_node.arguments
393+
names = arguments_node.arguments.filter_map { |arg| argument_name(arg) }
394+
names unless names.empty?
395+
end
396+
397+
def call_node_name_argument(call_node) # :nodoc:
398+
return unless call_node.arguments
399+
argument_name(call_node.arguments.arguments.first)
400+
end
401+
402+
def argument_name(argument_node) # :nodoc:
403+
case argument_node
404+
when Prism::SymbolNode
405+
argument_node.value
406+
when Prism::StringNode
407+
argument_node.unescaped
408+
end
401409
end
402410

403411
# Handles meta method comments
@@ -413,7 +421,7 @@ def handle_meta_method_comment(comment, directives, node)
413421
case directive
414422
when 'attr', 'attr_reader', 'attr_writer', 'attr_accessor'
415423
attributes = [param] if param
416-
attributes ||= call_node_name_arguments(node).compact if is_call_node
424+
attributes ||= call_node_name_arguments(node) if is_call_node
417425
rw = directive == 'attr_writer' ? 'W' : directive == 'attr_accessor' ? 'RW' : 'R'
418426
when 'method'
419427
method_name = param if param
@@ -439,7 +447,7 @@ def handle_meta_method_comment(comment, directives, node)
439447
mark_container_documentable(@container)
440448
end
441449
elsif line_no || node
442-
method_name ||= call_node_name_arguments(node).first if is_call_node
450+
method_name ||= call_node_name_argument(node) if is_call_node
443451
if node
444452
tokens = syntax_highlighted_tokens(node)
445453
line_no = node.location.start_line
@@ -1233,8 +1241,7 @@ def constant_arguments_names(call_node)
12331241
end
12341242

12351243
def call_node_name_arguments(call_node)
1236-
names = @scanner.call_node_name_arguments(call_node).compact
1237-
names unless names.empty?
1244+
@scanner.call_node_name_arguments(call_node)
12381245
end
12391246

12401247
def symbol_arguments(call_node)

0 commit comments

Comments
 (0)