@@ -35,17 +35,17 @@ def initialize(top_level, content, options, stats)
3535 @container = top_level
3636 @visibility = :public
3737 @singleton = false
38- @include_extend_suppressed = false
38+ @in_proc_block = false
3939 end
4040
4141 # Suppress `extend` and `include` within block
4242 # because they might be a metaprogramming block
4343 # example: `Module.new { include M }` `M.module_eval { include N }`
4444
45- def suppress_include_extend
46- @include_extend_suppressed = true
45+ def with_in_proc_block
46+ @in_proc_block = true
4747 yield
48- @include_extend_suppressed = false
48+ @in_proc_block = false
4949 end
5050
5151 # Dive into another container
@@ -54,11 +54,11 @@ def with_container(container, singleton: false)
5454 old_container = @container
5555 old_visibility = @visibility
5656 old_singleton = @singleton
57- old_include_extend_suppressed = @include_extend_suppressed
57+ old_in_proc_block = @in_proc_block
5858 @visibility = :public
5959 @container = container
6060 @singleton = singleton
61- @include_extend_suppressed = false
61+ @in_proc_block = false
6262 unless singleton
6363 # Need to update module parent chain to emulate Module.nesting.
6464 # This mechanism is inaccurate and needs to be fixed.
@@ -70,7 +70,7 @@ def with_container(container, singleton: false)
7070 @container = old_container
7171 @visibility = old_visibility
7272 @singleton = old_singleton
73- @include_extend_suppressed = old_include_extend_suppressed
73+ @in_proc_block = old_in_proc_block
7474 @module_nesting . pop
7575 end
7676
@@ -484,7 +484,7 @@ def add_attributes(names, rw, line_no)
484484 end
485485
486486 def add_includes_extends ( names , rdoc_class , line_no ) # :nodoc:
487- return if @include_extend_suppressed
487+ return if @in_proc_block
488488 comment = consecutive_comment ( line_no )
489489 handle_consecutive_comment_directive ( @container , comment )
490490 names . each do |name |
@@ -511,6 +511,8 @@ def add_extends(names, line_no) # :nodoc:
511511 # Adds a method defined by `def` syntax
512512
513513 def add_method ( name , receiver_name :, receiver_fallback_type :, visibility :, singleton :, params :, calls_super :, block_params :, tokens :, start_line :, end_line :)
514+ return if @in_proc_block
515+
514516 receiver = receiver_name ? find_or_create_module_path ( receiver_name , receiver_fallback_type ) : @container
515517 meth = RDoc ::AnyMethod . new ( nil , name )
516518 if ( comment = consecutive_comment ( start_line ) )
@@ -525,14 +527,13 @@ def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singl
525527 handle_modifier_directive ( meth , end_line )
526528 return unless should_document? ( meth )
527529
528-
529530 if meth . name == 'initialize' && !singleton
530531 if meth . dont_rename_initialize
531- visibility = :protected
532+ meth . visibility = :protected
532533 else
533534 meth . name = 'new'
534- singleton = true
535- visibility = :public
535+ meth . singleton = true
536+ meth . visibility = :public
536537 end
537538 end
538539
@@ -770,9 +771,8 @@ def visit_call_node(node)
770771 end
771772
772773 def visit_block_node ( node )
773- @scanner . suppress_include_extend do
774- # include and extend inside block are not documentable
775- # method definition might also not work but document it for now.
774+ @scanner . with_in_proc_block do
775+ # include, extend and method definition inside block are not documentable
776776 super
777777 end
778778 end
0 commit comments