@@ -510,13 +510,21 @@ def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singl
510510
511511 receiver = receiver_name ? find_or_create_module_path ( receiver_name , receiver_fallback_type ) : @container
512512 meth = RDoc ::AnyMethod . new ( nil , name , singleton : singleton )
513+
513514 if ( comment = consecutive_comment ( start_line ) )
514515 handle_consecutive_comment_directive ( @container , comment )
515516 handle_consecutive_comment_directive ( meth , comment )
516517
517518 comment . normalize
518519 meth . call_seq = comment . extract_call_seq
520+
521+ # Save visibility before comment assignment (where YARD processing happens)
522+ visibility_before = meth . visibility
519523 meth . comment = comment
524+ # Check if YARD tags changed the visibility
525+ if meth . visibility != visibility_before
526+ visibility = meth . visibility
527+ end
520528 end
521529 handle_modifier_directive ( meth , start_line )
522530 handle_modifier_directive ( meth , args_end_line )
@@ -527,7 +535,7 @@ def add_method(name, receiver_name:, receiver_fallback_type:, visibility:, singl
527535 receiver ,
528536 meth ,
529537 line_no : start_line ,
530- visibility : visibility ,
538+ visibility : visibility , # Use YARD visibility if set, otherwise use Ruby visibility
531539 params : params ,
532540 calls_super : calls_super ,
533541 block_params : block_params ,
0 commit comments