Skip to content

Commit

Permalink
List class ancestors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisbernard committed Sep 14, 2024
1 parent cf2067f commit a392e29
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
10 changes: 10 additions & 0 deletions lib/rdoc/code_object/class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,16 @@ def superclass=(superclass)
@superclass = superclass
end

def super_classes
result = []
parent = self
while parent = parent.superclass
result << parent
return result if parent.is_a?(String)
end
result
end

def to_s # :nodoc:
if is_alias_for then
"#{self.class.name} #{self.full_name} -> #{is_alias_for}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>
<% end %>

<% if (instance_methods = klass.instance_method_list.sort).any? %>
<% if (instance_methods = klass.instance_methods.sort).any? %>
<div class="nav-section">
<h3>Instance Methods</h3>
<ul class="link-list" role="directory">
Expand Down
25 changes: 18 additions & 7 deletions lib/rdoc/generator/template/rorvswild/_sidebar_parent.rhtml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<%- if klass.type == 'class' then %>
<div class="nav-section">
<h3>Parent</h3>
<ul class="link-list">
<%- if klass.superclass and not String === klass.superclass then -%>
<li><a href="<%= klass.aref_to klass.superclass.path %>"><%= klass.superclass.full_name %></a>
<%- else -%>
<li><%= klass.superclass %>
<%- end -%>
<h3>Ancestors</h3>
<ul class="link-list" role="directory">
<% for ancestor in (ancestors = klass.super_classes.reverse << klass) %>
<% if ancestor.is_a?(String) %>
<li>
<%= ancestor %>
<ul class="link-list" role="directory">
<% elsif ancestor.is_a?(RDoc::NormalClass) %>
<li>
<a href="<%= ancestor.aref_to ancestor.path %>"><%= ancestor.full_name %></a>
<ul class="link-list" role="directory">
<% end %>
<% end %>

<% for ancestor in ancestors %>
</ul>
</li>
<% end %>
</ul>
</div>
<%- end -%>

0 comments on commit a392e29

Please sign in to comment.