@@ -16,7 +16,7 @@ class RDoc::Parser::PrismRuby < RDoc::Parser
1616 parse_files_matching ( /\. rbw?$/ ) if ENV [ 'RDOC_USE_PRISM_PARSER' ]
1717
1818 attr_accessor :visibility
19- attr_reader :container , :singleton
19+ attr_reader :container , :singleton , :in_proc_block
2020
2121 def initialize ( top_level , content , options , stats )
2222 super
@@ -43,9 +43,10 @@ def initialize(top_level, content, options, stats)
4343 # example: `Module.new { include M }` `M.module_eval { include N }`
4444
4545 def with_in_proc_block
46+ in_proc_block = @in_proc_block
4647 @in_proc_block = true
4748 yield
48- @in_proc_block = false
49+ @in_proc_block = in_proc_block
4950 end
5051
5152 # Dive into another container
@@ -480,7 +481,6 @@ def add_attributes(names, rw, line_no)
480481 # Adds includes/extends. Module name is resolved to full before adding.
481482
482483 def add_includes_extends ( names , rdoc_class , line_no ) # :nodoc:
483- return if @in_proc_block
484484 comment , directives = consecutive_comment ( line_no )
485485 handle_code_object_directives ( @container , directives ) if directives
486486 names . each do |name |
@@ -508,8 +508,6 @@ def add_extends(names, line_no) # :nodoc:
508508 # Adds a method defined by `def` syntax
509509
510510 def add_method ( method_name , receiver_name :, receiver_fallback_type :, visibility :, singleton :, params :, calls_super :, block_params :, tokens :, start_line :, args_end_line :, end_line :)
511- return if @in_proc_block
512-
513511 receiver = receiver_name ? find_or_create_module_path ( receiver_name , receiver_fallback_type ) : @container
514512 comment , directives = consecutive_comment ( start_line )
515513 handle_code_object_directives ( @container , directives ) if directives
@@ -774,12 +772,14 @@ def visit_call_node(node)
774772
775773 def visit_block_node ( node )
776774 @scanner . with_in_proc_block do
777- # include, extend and method definition inside block are not documentable
775+ # include, extend and method definition inside block are not documentable.
776+ # visibility methods and attribute definition methods should be ignored inside block.
778777 super
779778 end
780779 end
781780
782781 def visit_alias_method_node ( node )
782+ return if @scanner . in_proc_block
783783 @scanner . process_comments_until ( node . location . start_line - 1 )
784784 return unless node . old_name . is_a? ( Prism ::SymbolNode ) && node . new_name . is_a? ( Prism ::SymbolNode )
785785 @scanner . add_alias_method ( node . old_name . value . to_s , node . new_name . value . to_s , node . location . start_line )
@@ -858,6 +858,8 @@ def visit_def_node(node)
858858 end_line = node . location . end_line
859859 @scanner . process_comments_until ( start_line - 1 )
860860
861+ return if @scanner . in_proc_block
862+
861863 case node . receiver
862864 when Prism ::NilNode , Prism ::TrueNode , Prism ::FalseNode
863865 visibility = :public
@@ -996,19 +998,20 @@ def _visit_call_require(call_node)
996998
997999 def _visit_call_module_function ( call_node )
9981000 yield
999- return if @scanner . singleton
1001+ return if @scanner . in_proc_block || @scanner . singleton
10001002 names = visibility_method_arguments ( call_node , singleton : false ) &.map ( &:to_s )
10011003 @scanner . change_method_to_module_function ( names ) if names
10021004 end
10031005
10041006 def _visit_call_public_private_class_method ( call_node , visibility )
10051007 yield
1006- return if @scanner . singleton
1008+ return if @scanner . in_proc_block || @scanner . singleton
10071009 names = visibility_method_arguments ( call_node , singleton : true )
10081010 @scanner . change_method_visibility ( names , visibility , singleton : true ) if names
10091011 end
10101012
10111013 def _visit_call_public_private_protected ( call_node , visibility )
1014+ return if @scanner . in_proc_block
10121015 arguments_node = call_node . arguments
10131016 if arguments_node . nil? # `public` `private`
10141017 @scanner . visibility = visibility
@@ -1020,12 +1023,16 @@ def _visit_call_public_private_protected(call_node, visibility)
10201023 end
10211024
10221025 def _visit_call_alias_method ( call_node )
1026+ return if @scanner . in_proc_block
1027+
10231028 new_name , old_name , *rest = symbol_arguments ( call_node )
10241029 return unless old_name && new_name && rest . empty?
10251030 @scanner . add_alias_method ( old_name . to_s , new_name . to_s , call_node . location . start_line )
10261031 end
10271032
10281033 def _visit_call_include ( call_node )
1034+ return if @scanner . in_proc_block
1035+
10291036 names = constant_arguments_names ( call_node )
10301037 line_no = call_node . location . start_line
10311038 return unless names
@@ -1038,26 +1045,30 @@ def _visit_call_include(call_node)
10381045 end
10391046
10401047 def _visit_call_extend ( call_node )
1048+ return if @scanner . in_proc_block
1049+
10411050 names = constant_arguments_names ( call_node )
10421051 @scanner . add_extends ( names , call_node . location . start_line ) if names && !@scanner . singleton
10431052 end
10441053
10451054 def _visit_call_public_constant ( call_node )
1046- return if @scanner . singleton
1055+ return if @scanner . in_proc_block || @scanner . singleton
10471056 names = symbol_arguments ( call_node )
10481057 @scanner . container . set_constant_visibility_for ( names . map ( &:to_s ) , :public ) if names
10491058 end
10501059
10511060 def _visit_call_private_constant ( call_node )
1052- return if @scanner . singleton
1061+ return if @scanner . in_proc_block || @scanner . singleton
10531062 names = symbol_arguments ( call_node )
10541063 @scanner . container . set_constant_visibility_for ( names . map ( &:to_s ) , :private ) if names
10551064 end
10561065
10571066 def _visit_call_attr_reader_writer_accessor ( call_node , rw )
1067+ return if @scanner . in_proc_block
10581068 names = symbol_arguments ( call_node )
10591069 @scanner . add_attributes ( names . map ( &:to_s ) , rw , call_node . location . start_line ) if names
10601070 end
1071+
10611072 class MethodSignatureVisitor < Prism ::Visitor # :nodoc:
10621073 class << self
10631074 def scan_signature ( def_node )
0 commit comments