diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index 6e943e5d6d..bb90776b68 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -451,7 +451,6 @@ def handle_meta_method_comment(comment, directives, node) @container, comment: comment, directives: directives, - dont_rename_initialize: false, line_no: line_no, visibility: visibility, singleton: @singleton || singleton_method, @@ -722,7 +721,7 @@ def add_method(method_name, receiver_name:, receiver_fallback_type:, visibility: ) end - private def internal_add_method(method_name, container, comment:, dont_rename_initialize: false, directives:, modifier_comment_lines: nil, line_no:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:, type_signature_lines: nil) # :nodoc: + private def internal_add_method(method_name, container, comment:, directives:, modifier_comment_lines: nil, line_no:, visibility:, singleton:, params:, calls_super:, block_params:, tokens:, type_signature_lines: nil) # :nodoc: meth = RDoc::AnyMethod.new(method_name, singleton: singleton) meth.comment = comment handle_code_object_directives(meth, directives) if directives @@ -746,16 +745,10 @@ def add_method(method_name, receiver_name:, receiver_fallback_type:, visibility: meth.calls_super = calls_super meth.block_params ||= block_params if block_params meth.type_signature_lines = type_signature_lines - container.add_method(meth) - record_location(meth) - meth.start_collecting_tokens(:ruby) - tokens.each do |token| - meth.token_stream << token - end - # Rename after add_method to register duplicated 'new' and 'initialize' - # defined in c and ruby. - if !dont_rename_initialize && method_name == 'initialize' && !singleton + # An instance method `initialize` is documented as `::new` unless the + # :notnew: directive is given + if method_name == 'initialize' && !singleton if meth.dont_rename_initialize meth.visibility = :protected else @@ -764,6 +757,13 @@ def add_method(method_name, receiver_name:, receiver_fallback_type:, visibility: meth.visibility = :public end end + + record_location(meth) + container.add_method(meth) + meth.start_collecting_tokens(:ruby) + tokens.each do |token| + meth.token_stream << token + end end # Find or create module or class from a given module name using Ruby lexical