Permalink
Browse files

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
  • Loading branch information...
1 parent efff6bf commit 610b483a6a497d95b95529dad26f20a0ce335b23 @drbrain drbrain committed Dec 20, 2012
Showing with 48 additions and 4 deletions.
  1. +2 −0 History.rdoc
  2. +23 −4 lib/rdoc/parser/ruby.rb
  3. +23 −0 test/test_rdoc_parser_ruby.rb
View
@@ -20,6 +20,8 @@ to build HTML documentation when installing gems.)
smart enough to restore the source correctly. Bug #162 by Zachary Scott.
* Fixed parsing of executables with shebang and encoding comments. Bug #161
by Marcus Stollsteimer
+ * RDoc now ignores methods defined on constants instead of creating a fake
+ module. Bug #163 by Zachary Scott.
=== 4.0.0.preview2.1 / 2012-12-14
View
@@ -1116,6 +1116,18 @@ def parse_method(container, single, tk, comment)
name = name_t2.name
prev_container = container
container = container.find_module_named(name_t.name)
+
+ unless container then
+ constant = prev_container.constants.find do |const|
+ const.name == name_t.name
+ end
+
+ if constant then
+ parse_method_dummy prev_container
+ return
+ end
+ end
+
unless container then
added_container = true
obj = name_t.name.split("::").inject(Object) do |state, item|
@@ -1138,10 +1150,7 @@ def parse_method(container, single, tk, comment)
container.record_location @top_level
end
when TkIDENTIFIER, TkIVAR, TkGVAR then
- dummy = RDoc::Context.new
- dummy.parent = container
- dummy.store = container.store
- skip_method dummy
+ parse_method_dummy container
return
when TkTRUE, TkFALSE, TkNIL then
klass_name = "#{name_t.name.capitalize}Class"
@@ -1229,6 +1238,16 @@ def parse_method(container, single, tk, comment)
end
##
+ # Parses a method that needs to be ignored.
+
+ def parse_method_dummy container
+ dummy = RDoc::Context.new
+ dummy.parent = container
+ dummy.store = container.store
+ skip_method dummy
+ end
+
+ ##
# Extracts +yield+ parameters from +method+
def parse_method_or_yield_parameters(method = nil,
@@ -1525,6 +1525,21 @@ def test_parse_method_ampersand
assert ampersand.singleton
end
+ def test_parse_method_constant
+ c = RDoc::Constant.new 'CONST', nil, ''
+ m = @top_level.add_class RDoc::NormalModule, 'M'
+ m.add_constant c
+
+ util_parser "def CONST.m() end"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method m, RDoc::Parser::Ruby::NORMAL, tk, @comment
+
+ assert_empty @store.modules_hash.keys
+ assert_equal %w[M], @store.classes_hash.keys
+ end
+
def test_parse_method_false
util_parser "def false.foo() :bar end"
@@ -1766,6 +1781,14 @@ def test_parse_method_utf8
assert_equal "def \317\211", omega.text
end
+ def test_parse_method_dummy
+ util_parser ".method() end"
+
+ @parser.parse_method_dummy @top_level
+
+ assert_nil @parser.get_tk
+ end
+
def test_parse_method_or_yield_parameters_hash
util_parser "({})\n"

0 comments on commit 610b483

Please sign in to comment.