Skip to content

Commit

Permalink
Add method RDoc::ClassModule#super_classes
Browse files Browse the repository at this point in the history
The purpose is to list all class ancestors in a new theme (see PR ruby#1182).
  • Loading branch information
alexisbernard committed Sep 30, 2024
1 parent b7d580a commit c88c36e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 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,20 @@ def superclass=(superclass)
@superclass = superclass
end

##
# Get all super classes of this class in an array. The last element might be
# a string if the name is unknown.

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
6 changes: 6 additions & 0 deletions test/rdoc/test_rdoc_class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,12 @@ def test_superclass
assert_equal @c3_h1, @c3_h2.superclass
end

def test_super_classes
rdoc_c3_h1 = @xref_data.find_module_named('C3::H1')
rdoc_object = @xref_data.find_module_named('Object')
assert_equal [rdoc_c3_h1, rdoc_object, "BasicObject"], @c3_h2.super_classes
end

def test_update_aliases_class
n1 = @xref_data.add_module RDoc::NormalClass, 'N1'
n1_k2 = n1.add_module RDoc::NormalClass, 'N2'
Expand Down

0 comments on commit c88c36e

Please sign in to comment.