diff options
author | Jeremy Evans <[email protected]> | 2023-02-19 14:46:13 -0800 |
---|---|---|
committer | git <[email protected]> | 2023-09-05 00:45:42 +0000 |
commit | 3f6c92e9d592a2b122fb2260fccee7a7dd850cb8 (patch) | |
tree | 424e44f808f86e80a4db7741fabb288281259897 /lib/rdoc | |
parent | a14ba622da01c7774d0fb285b183097d19e3675e (diff) |
[ruby/rdoc] Omit descriptions and parameter lists for methods defined in C not mentioned in call-seq
This allows RDoc to better generate documentation for methods
following the Ruby core documentation guide (which omits aliases
in call-seq in most cases). This makes documentation for methods
defined in C more similar to methods defined in Ruby. For methods
defined in Ruby, the method description of the aliased method is
already not used (you have to explicitly document the alias to
use it).
Internally, this adds AnyMethod#has_call_seq? and #skip_description?,
and updates Darkfish to:
* only show the method name if there is a call-seq for the method,
but the call-seq omits the method
* to omit the method description if the method is an alias or has
aliases and has a call-seq that does not include the method
See discussion in https://github.com/ruby/ruby/pull/7316 for
details.
https://github.com/ruby/rdoc/commit/e3688de49b
Diffstat (limited to 'lib/rdoc')
-rw-r--r-- | lib/rdoc/any_method.rb | 15 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/class.rhtml | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/rdoc/any_method.rb b/lib/rdoc/any_method.rb index 051f946a10..465c4a4fb2 100644 --- a/lib/rdoc/any_method.rb +++ b/lib/rdoc/any_method.rb @@ -116,6 +116,13 @@ class RDoc::AnyMethod < RDoc::MethodAttr end ## + # Whether the method has a call-seq. + + def has_call_seq? + !!(@call_seq || is_alias_for&._call_seq) + end + + ## # Loads is_alias_for from the internal name. Returns nil if the alias # cannot be found. @@ -297,6 +304,14 @@ class RDoc::AnyMethod < RDoc::MethodAttr end ## + # Whether to skip the method description, true for methods that have + # aliases with a call-seq that doesn't include the method name. + + def skip_description? + has_call_seq? && call_seq.nil? && !!(is_alias_for || !aliases.empty?) + end + + ## # Sets the store for this method and its referenced code objects. def store= store diff --git a/lib/rdoc/generator/template/darkfish/class.rhtml b/lib/rdoc/generator/template/darkfish/class.rhtml index 97d175dddc..d6510336df 100644 --- a/lib/rdoc/generator/template/darkfish/class.rhtml +++ b/lib/rdoc/generator/template/darkfish/class.rhtml @@ -112,6 +112,10 @@ <%- end -%> </div> <%- end -%> + <%- elsif method.has_call_seq? then -%> + <div class="method-heading"> + <span class="method-name"><%= h method.name %></span> + </div> <%- else -%> <div class="method-heading"> <span class="method-name"><%= h method.name %></span><span @@ -123,6 +127,7 @@ <%- end -%> </div> + <%- unless method.skip_description? then -%> <div class="method-description"> <%- if method.comment then -%> <%= method.description.strip %> @@ -145,6 +150,7 @@ </div> <%- end -%> </div> + <%- end -%> <%- unless method.aliases.empty? then -%> <div class="aliases"> |