Skip to content

Commit

Permalink
Rename to nesting_namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
unasuke committed Jul 6, 2023
1 parent a9cc077 commit 11d3c95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions lib/rdoc/class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,19 @@ def full_name
##
# Return array of full_name splitted by +::+.

def namespaces
def nesting_namespaces
@namespaces ||= full_name.split("::").reject(&:empty?)
end

##
# Return array of fully qualified namespaces.
# Return array of fully qualified nesting namespaces.
#
# For example, if full_name is +A::B::C+, this method returns <code>["A", "A::B", "A::B::C"]</code>

def fully_qualified_namespaces
return namespaces if namespaces.length < 2
@fqns ||= namespaces.map.with_index do |_, i|
namespaces[0..i].join("::")
def fully_qualified_nesting_namespaces
return nesting_namespaces if nesting_namespaces.length < 2
@fqns ||= nesting_namespaces.map.with_index do |_, i|
nesting_namespaces[0..i].join("::")
end
end

Expand Down
16 changes: 8 additions & 8 deletions test/rdoc/test_rdoc_class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1500,25 +1500,25 @@ def test_update_extends_with_colons
assert_equal [a, c], @c1.extends
end

def test_namespaces
def test_nesting_namespaces
cm1 = RDoc::ClassModule.new "A"
assert_equal ["A"], cm1.namespaces
assert_equal ["A"], cm1.nesting_namespaces

cm2 = RDoc::ClassModule.new "A::B"
assert_equal ["A", "B"], cm2.namespaces
assert_equal ["A", "B"], cm2.nesting_namespaces

cm3 = RDoc::ClassModule.new "::A::B::C"
assert_equal ["A", "B", "C"], cm3.namespaces
assert_equal ["A", "B", "C"], cm3.nesting_namespaces
end

def test_fully_qualified_namespaces
def test_fully_qualified_nesting_namespaces
cm1 = RDoc::ClassModule.new "A"
assert_equal ["A"], cm1.fully_qualified_namespaces
assert_equal ["A"], cm1.fully_qualified_nesting_namespaces

cm2 = RDoc::ClassModule.new "A::B"
assert_equal ["A", "A::B"], cm2.fully_qualified_namespaces
assert_equal ["A", "A::B"], cm2.fully_qualified_nesting_namespaces

cm3 = RDoc::ClassModule.new "::A::B::C"
assert_equal ["A", "A::B", "A::B::C"], cm3.fully_qualified_namespaces
assert_equal ["A", "A::B", "A::B::C"], cm3.fully_qualified_nesting_namespaces
end
end

0 comments on commit 11d3c95

Please sign in to comment.