Skip to content

Remove "##" from a comment to require#9306

Merged
colby-swandale merged 1 commit intoruby:masterfrom
tompng:require_is_not_a_metaprogramming_method
Feb 5, 2026
Merged

Remove "##" from a comment to require#9306
colby-swandale merged 1 commit intoruby:masterfrom
tompng:require_is_not_a_metaprogramming_method

Conversation

@tompng
Copy link
Member

@tompng tompng commented Feb 4, 2026

In RDoc, comment that starts with "##" is a metaprogramming method definition. If it's not a metaprogramming method definition, "##" shouldn't be used.

What was the end-user or developer problem that led to this PR?

In RDoc's experimental ruby parser, comment below will add a "rubygems/defaults/operating_system" method and "unknown" method to the documentation.

##
# comment
require "rubygems/defaults/operating_system"

##
# comment
require "rubygems/defaults/#{RUBY_ENGINE}"

Reason:

class A
  ##
  # If a comment starts with '##', it is a metaprogramming method.
  # If `:method: methodname` directive is not used, RDoc uses the first
  # symbol/string argument as method name to be documented.
  define_metaprogramming_method "abc", metaprogramming_arguments

  ##
  # Defines method "foo/bar" in both released RDoc and in experimental RDoc parser
  require_relative "foo/bar"

  ##
  # Defines method "foo/baz" only in experimental RDoc parser.
  # Released RDoc somehow ignores this case for unknown reason.
  require "foo/baz"
end

This pull request will prevent it.

What is your fix for the problem, implemented in this PR?

Make sure the following tasks are checked

In RDoc, comment that starts with "##" is a metaprogramming method definition.
If it's not a metaprogramming method definition, "##" shouldn't be used.
@colby-swandale colby-swandale merged commit 2ca7803 into ruby:master Feb 5, 2026
89 checks passed
@hsbt
Copy link
Member

hsbt commented Feb 5, 2026

@tompng Thanks.

In RDoc, comment that starts with "##" is a metaprogramming method definition. If it's not a metaprogramming method definition, "##" shouldn't be used.

Is it documented behavior?

@tompng tompng deleted the require_is_not_a_metaprogramming_method branch February 5, 2026 07:53
@tompng
Copy link
Member Author

tompng commented Feb 5, 2026

Is it documented behavior?

Yes. Documented here https://ruby.github.io/rdoc/RDoc/Parser/Ruby.html#class-rdoc-parser-ruby-metaprogrammed-methods

To pick up a metaprogrammed method, the parser looks for a comment starting with ‘##’ before an identifier:

##
# This is a meta-programmed method!

add_my_method :meta_method, :arg1, :arg2

The parser looks at the token after the identifier to determine the name, in this example, :meta_method. If a name cannot be found, a warning is printed and ‘unknown’ is used.

@hsbt
Copy link
Member

hsbt commented Feb 5, 2026

I see. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants