Skip to content

Commit 810913a

Browse files
committed
Singleton method visibility should be isolated
Each singleton method definition of the form `def recv.method` has visibility separate from the outer scope and is set to `public` by default.
1 parent b2a35ee commit 810913a

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

lib/rdoc/parser/ruby.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,12 @@ def parse_method(container, single, tk, comment)
14531453
meth = RDoc::AnyMethod.new get_tkread, name
14541454
look_for_directives_in meth, comment
14551455
meth.singleton = single == SINGLE ? true : singleton
1456+
if singleton
1457+
# `current_line_visibility' is useless because it works against
1458+
# the normal method named as same as the singleton method, after
1459+
# the latter was defined. Of course these are different things.
1460+
container.current_line_visibility = :public
1461+
end
14561462

14571463
record_location meth
14581464
meth.line = line_no

test/rdoc/test_rdoc_context.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,8 @@ def test_visibility_def
927927
assert_equal :private, @c6.find_method_named('priv6').visibility
928928
assert_equal :protected, @c6.find_method_named('prot6').visibility
929929
assert_equal :public, @c6.find_method_named('pub6').visibility
930+
assert_equal :public, @c6.find_method_named('s_pub1').visibility
931+
assert_equal :public, @c6.find_method_named('s_pub3').visibility
930932
end
931933

932934
def util_visibilities

test/rdoc/xref_data.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def priv3() end
7474
def priv4() end
7575
public def pub5() end
7676
def priv5() end
77+
def self.s_pub1() end
7778
7879
protected
7980
private def priv6() end
@@ -82,6 +83,7 @@ def prot3() end
8283
def prot5() end
8384
public def pub6() end
8485
def prot6() end
86+
def self.s_pub3() end
8587
end
8688
8789
class C7

0 commit comments

Comments
 (0)