@@ -35,6 +35,17 @@ def initialize(top_level, content, options, stats)
3535 @container = top_level
3636 @visibility = :public
3737 @singleton = false
38+ @include_extend_suppressed = false
39+ end
40+
41+ # Suppress `extend` and `include` within block
42+ # because they might be a metaprogramming block
43+ # example: `Module.new { include M }` `M.module_eval { include N }`
44+
45+ def suppress_include_extend
46+ @include_extend_suppressed = true
47+ yield
48+ @include_extend_suppressed = false
3849 end
3950
4051 # Dive into another container
@@ -43,9 +54,11 @@ def with_container(container, singleton: false)
4354 old_container = @container
4455 old_visibility = @visibility
4556 old_singleton = @singleton
57+ old_include_extend_suppressed = @include_extend_suppressed
4658 @visibility = :public
4759 @container = container
4860 @singleton = singleton
61+ @include_extend_suppressed = false
4962 unless singleton
5063 @module_nesting . push container
5164
@@ -58,6 +71,7 @@ def with_container(container, singleton: false)
5871 @container = old_container
5972 @visibility = old_visibility
6073 @singleton = old_singleton
74+ @include_extend_suppressed = old_include_extend_suppressed
6175 @module_nesting . pop unless singleton
6276 end
6377
@@ -471,6 +485,7 @@ def add_attributes(names, rw, line_no)
471485 end
472486
473487 def add_includes_extends ( names , rdoc_class , line_no ) # :nodoc:
488+ return if @include_extend_suppressed
474489 comment = consecutive_comment ( line_no )
475490 handle_consecutive_comment_directive ( @container , comment )
476491 names . each do |name |
@@ -736,13 +751,22 @@ def visit_call_node(node)
736751 when :private_class_method
737752 _visit_call_public_private_class_method ( node , :private ) { super }
738753 else
754+ node . arguments &.accept ( self )
739755 super
740756 end
741757 else
742758 super
743759 end
744760 end
745761
762+ def visit_block_node ( node )
763+ @scanner . suppress_include_extend do
764+ # include and extend inside block are not documentable
765+ # method definition might also not work but document it for now.
766+ super
767+ end
768+ end
769+
746770 def visit_alias_method_node ( node )
747771 @scanner . process_comments_until ( node . location . start_line - 1 )
748772 return unless node . old_name . is_a? ( Prism ::SymbolNode ) && node . new_name . is_a? ( Prism ::SymbolNode )
0 commit comments