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

Singleton visibility #1080

Merged
merged 2 commits into from
Jan 7, 2024
Merged
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
7 changes: 7 additions & 0 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,12 @@ def parse_method(container, single, tk, comment)
meth = RDoc::AnyMethod.new get_tkread, name
look_for_directives_in meth, comment
meth.singleton = single == SINGLE ? true : singleton
if singleton
# `current_line_visibility' is useless because it works against
# the normal method named as same as the singleton method, after
# the latter was defined. Of course these are different things.
container.current_line_visibility = :public
end

record_location meth
meth.line = line_no
Expand Down Expand Up @@ -1776,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
6 changes: 6 additions & 0 deletions test/rdoc/test_rdoc_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,12 @@ def test_visibility_def
assert_equal :private, @c6.find_method_named('priv6').visibility
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
12 changes: 12 additions & 0 deletions test/rdoc/xref_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def priv3() end
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 @@ -82,6 +88,12 @@ def prot3() end
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