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

Add method RDoc::ClassModule#super_classes #1183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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