Skip to content

Commit

Permalink
Visibility should begin from public for each scope
Browse files Browse the repository at this point in the history
Even for singleton class definition such as `class << self` that
shares the same container with the outer scope, its visibility is
separated and set to `public` by default.
  • Loading branch information
nobu committed Jan 7, 2024
1 parent 810913a commit baf2636
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,7 @@ def parse_statements(container, single = NORMAL, current_method = nil,

nest = 1
save_visibility = container.visibility
container.visibility = :public unless current_method

non_comment_seen = true

Expand Down
4 changes: 4 additions & 0 deletions test/rdoc/test_rdoc_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,11 @@ def test_visibility_def
assert_equal :protected, @c6.find_method_named('prot6').visibility
assert_equal :public, @c6.find_method_named('pub6').visibility
assert_equal :public, @c6.find_method_named('s_pub1').visibility
assert_equal :public, @c6.find_method_named('s_pub2').visibility
assert_equal :public, @c6.find_method_named('s_pub3').visibility
assert_equal :public, @c6.find_method_named('s_pub4').visibility
assert_equal :private, @c6.find_method_named('s_priv1').visibility
assert_equal :protected, @c6.find_method_named('s_prot1').visibility
end

def util_visibilities
Expand Down
10 changes: 10 additions & 0 deletions test/rdoc/xref_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def priv4() end
public def pub5() end
def priv5() end
def self.s_pub1() end
class << self
def s_pub2() end
private
def s_priv1() end
end
protected
private def priv6() end
Expand All @@ -84,6 +89,11 @@ def prot5() end
public def pub6() end
def prot6() end
def self.s_pub3() end
class << self
def s_pub4() end
protected
def s_prot1() end
end
end
class C7
Expand Down

0 comments on commit baf2636

Please sign in to comment.