Skip to content

Commit 610b483

Browse files
committed
Ignore methods defined on constants
RDoc would create a module for a method defined on a constant. Since the module isn't real this is too confusing. Fixes bug #163
1 parent efff6bf commit 610b483

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

History.rdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ to build HTML documentation when installing gems.)
2020
smart enough to restore the source correctly. Bug #162 by Zachary Scott.
2121
* Fixed parsing of executables with shebang and encoding comments. Bug #161
2222
by Marcus Stollsteimer
23+
* RDoc now ignores methods defined on constants instead of creating a fake
24+
module. Bug #163 by Zachary Scott.
2325

2426
=== 4.0.0.preview2.1 / 2012-12-14
2527

lib/rdoc/parser/ruby.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,18 @@ def parse_method(container, single, tk, comment)
11161116
name = name_t2.name
11171117
prev_container = container
11181118
container = container.find_module_named(name_t.name)
1119+
1120+
unless container then
1121+
constant = prev_container.constants.find do |const|
1122+
const.name == name_t.name
1123+
end
1124+
1125+
if constant then
1126+
parse_method_dummy prev_container
1127+
return
1128+
end
1129+
end
1130+
11191131
unless container then
11201132
added_container = true
11211133
obj = name_t.name.split("::").inject(Object) do |state, item|
@@ -1138,10 +1150,7 @@ def parse_method(container, single, tk, comment)
11381150
container.record_location @top_level
11391151
end
11401152
when TkIDENTIFIER, TkIVAR, TkGVAR then
1141-
dummy = RDoc::Context.new
1142-
dummy.parent = container
1143-
dummy.store = container.store
1144-
skip_method dummy
1153+
parse_method_dummy container
11451154
return
11461155
when TkTRUE, TkFALSE, TkNIL then
11471156
klass_name = "#{name_t.name.capitalize}Class"
@@ -1228,6 +1237,16 @@ def parse_method(container, single, tk, comment)
12281237
@stats.add_method meth
12291238
end
12301239

1240+
##
1241+
# Parses a method that needs to be ignored.
1242+
1243+
def parse_method_dummy container
1244+
dummy = RDoc::Context.new
1245+
dummy.parent = container
1246+
dummy.store = container.store
1247+
skip_method dummy
1248+
end
1249+
12311250
##
12321251
# Extracts +yield+ parameters from +method+
12331252

test/test_rdoc_parser_ruby.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,21 @@ def test_parse_method_ampersand
15251525
assert ampersand.singleton
15261526
end
15271527

1528+
def test_parse_method_constant
1529+
c = RDoc::Constant.new 'CONST', nil, ''
1530+
m = @top_level.add_class RDoc::NormalModule, 'M'
1531+
m.add_constant c
1532+
1533+
util_parser "def CONST.m() end"
1534+
1535+
tk = @parser.get_tk
1536+
1537+
@parser.parse_method m, RDoc::Parser::Ruby::NORMAL, tk, @comment
1538+
1539+
assert_empty @store.modules_hash.keys
1540+
assert_equal %w[M], @store.classes_hash.keys
1541+
end
1542+
15281543
def test_parse_method_false
15291544
util_parser "def false.foo() :bar end"
15301545

@@ -1766,6 +1781,14 @@ def test_parse_method_utf8
17661781
assert_equal "def \317\211", omega.text
17671782
end
17681783

1784+
def test_parse_method_dummy
1785+
util_parser ".method() end"
1786+
1787+
@parser.parse_method_dummy @top_level
1788+
1789+
assert_nil @parser.get_tk
1790+
end
1791+
17691792
def test_parse_method_or_yield_parameters_hash
17701793
util_parser "({})\n"
17711794

0 commit comments

Comments
 (0)