Skip to content

Commit e3688de

Browse files
jeremyevansnobu
authored andcommitted
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 ruby/ruby#7316 for details.
1 parent 572471c commit e3688de

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

lib/rdoc/any_method.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ def call_seq= call_seq
115115
@call_seq = call_seq
116116
end
117117

118+
##
119+
# Whether the method has a call-seq.
120+
121+
def has_call_seq?
122+
!!(@call_seq || is_alias_for&._call_seq)
123+
end
124+
118125
##
119126
# Loads is_alias_for from the internal name. Returns nil if the alias
120127
# cannot be found.
@@ -296,6 +303,14 @@ def param_seq
296303
params
297304
end
298305

306+
##
307+
# Whether to skip the method description, true for methods that have
308+
# aliases with a call-seq that doesn't include the method name.
309+
310+
def skip_description?
311+
has_call_seq? && call_seq.nil? && !!(is_alias_for || !aliases.empty?)
312+
end
313+
299314
##
300315
# Sets the store for this method and its referenced code objects.
301316

lib/rdoc/generator/template/darkfish/class.rhtml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
<%- end -%>
113113
</div>
114114
<%- end -%>
115+
<%- elsif method.has_call_seq? then -%>
116+
<div class="method-heading">
117+
<span class="method-name"><%= h method.name %></span>
118+
</div>
115119
<%- else -%>
116120
<div class="method-heading">
117121
<span class="method-name"><%= h method.name %></span><span
@@ -123,6 +127,7 @@
123127
<%- end -%>
124128
</div>
125129

130+
<%- unless method.skip_description? then -%>
126131
<div class="method-description">
127132
<%- if method.comment then -%>
128133
<%= method.description.strip %>
@@ -145,6 +150,7 @@
145150
</div>
146151
<%- end -%>
147152
</div>
153+
<%- end -%>
148154

149155
<%- unless method.aliases.empty? then -%>
150156
<div class="aliases">

test/rdoc/test_rdoc_any_method.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ def test_full_name
6969
assert_equal 'C1::m', @c1.method_list.first.full_name
7070
end
7171

72+
def test_has_call_seq?
73+
m = RDoc::AnyMethod.new nil, "each_line"
74+
m2 = RDoc::AnyMethod.new nil, "each"
75+
assert_equal false, m.has_call_seq?
76+
m.call_seq = "each_line()"
77+
assert_equal true, m.has_call_seq?
78+
79+
m = RDoc::AnyMethod.new nil, "each_line"
80+
m.is_alias_for = m2
81+
assert_equal false, m.has_call_seq?
82+
m2.call_seq = "each_line()"
83+
assert_equal true, m.has_call_seq?
84+
end
85+
7286
def test_is_alias_for
7387
assert_equal @c2_b, @c2_a.is_alias_for
7488

@@ -515,6 +529,30 @@ def test_parent_name
515529
assert_equal 'C1', @c1.method_list.last.parent_name
516530
end
517531

532+
def test_skip_description?
533+
m = RDoc::AnyMethod.new nil, "each_line"
534+
m2 = RDoc::AnyMethod.new nil, "each"
535+
assert_equal false, m.skip_description?
536+
assert_equal false, m2.skip_description?
537+
538+
m.is_alias_for = m2
539+
m2.aliases << m
540+
assert_equal false, m.skip_description?
541+
assert_equal false, m2.skip_description?
542+
543+
m2.call_seq = "each()"
544+
assert_equal true, m.skip_description?
545+
assert_equal false, m2.skip_description?
546+
547+
m2.call_seq = "each_line()"
548+
assert_equal false, m.skip_description?
549+
assert_equal true, m2.skip_description?
550+
551+
m2.call_seq = "each()\neach_line()"
552+
assert_equal false, m.skip_description?
553+
assert_equal false, m2.skip_description?
554+
end
555+
518556
def test_store_equals
519557
loaded = Marshal.load Marshal.dump(@c1.method_list.last)
520558

0 commit comments

Comments
 (0)