Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit descriptions and parameter lists for methods defined in C not mentioned in call-seq #978

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/rdoc/any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ def call_seq= call_seq
@call_seq = call_seq
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.
Expand Down Expand Up @@ -296,6 +303,14 @@ def param_seq
params
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?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition around aliases with has_call_seq? seems complicated a little.

end

##
# Sets the store for this method and its referenced code objects.

Expand Down
6 changes: 6 additions & 0 deletions lib/rdoc/generator/template/darkfish/class.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -123,6 +127,7 @@
<%- end -%>
</div>

<%- unless method.skip_description? then -%>
<div class="method-description">
<%- if method.comment then -%>
<%= method.description.strip %>
Expand All @@ -145,6 +150,7 @@
</div>
<%- end -%>
</div>
<%- end -%>

<%- unless method.aliases.empty? then -%>
<div class="aliases">
Expand Down
38 changes: 38 additions & 0 deletions test/rdoc/test_rdoc_any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ def test_full_name
assert_equal 'C1::m', @c1.method_list.first.full_name
end

def test_has_call_seq?
m = RDoc::AnyMethod.new nil, "each_line"
m2 = RDoc::AnyMethod.new nil, "each"
assert_equal false, m.has_call_seq?
m.call_seq = "each_line()"
assert_equal true, m.has_call_seq?

m = RDoc::AnyMethod.new nil, "each_line"
m.is_alias_for = m2
assert_equal false, m.has_call_seq?
m2.call_seq = "each_line()"
assert_equal true, m.has_call_seq?
end

def test_is_alias_for
assert_equal @c2_b, @c2_a.is_alias_for

Expand Down Expand Up @@ -515,6 +529,30 @@ def test_parent_name
assert_equal 'C1', @c1.method_list.last.parent_name
end

def test_skip_description?
m = RDoc::AnyMethod.new nil, "each_line"
m2 = RDoc::AnyMethod.new nil, "each"
assert_equal false, m.skip_description?
assert_equal false, m2.skip_description?

m.is_alias_for = m2
m2.aliases << m
assert_equal false, m.skip_description?
assert_equal false, m2.skip_description?

m2.call_seq = "each()"
assert_equal true, m.skip_description?
assert_equal false, m2.skip_description?

m2.call_seq = "each_line()"
assert_equal false, m.skip_description?
assert_equal true, m2.skip_description?

m2.call_seq = "each()\neach_line()"
assert_equal false, m.skip_description?
assert_equal false, m2.skip_description?
end

def test_store_equals
loaded = Marshal.load Marshal.dump(@c1.method_list.last)

Expand Down