Skip to content

Commit b0054d5

Browse files
committed
Support :args: directive before method
The :args: directive is supported only by after "def" keyword line like below: def method_with_args_comment(*array) # :args: a, b, c end # => documented as method_with_args_comment(a, b, c) This commit changes to support like below: ## # :args: a, b, c def meth(*array) end # => documented as meth(a, b, c)
1 parent 1cfd7e8 commit b0054d5

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

lib/rdoc/markup/pre_process.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def handle_directive prefix, directive, param, code_object = nil,
150150

151151
case directive
152152
when 'arg', 'args' then
153-
return "#{prefix}:#{directive}: #{param}\n" unless code_object
153+
return "#{prefix}:#{directive}: #{param}\n" unless code_object && code_object.kind_of?(RDoc::AnyMethod)
154154

155155
code_object.params = param
156156

lib/rdoc/parser/ruby.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,15 @@ def suppress_parents container, ancestor # :nodoc:
574574
#
575575
# This routine modifies its +comment+ parameter.
576576

577-
def look_for_directives_in context, comment
578-
@preprocess.handle comment, context do |directive, param|
577+
def look_for_directives_in container, comment
578+
@preprocess.handle comment, container do |directive, param|
579579
case directive
580580
when 'method', 'singleton-method',
581581
'attr', 'attr_accessor', 'attr_reader', 'attr_writer' then
582582
false # handled elsewhere
583583
when 'section' then
584-
context.set_current_section param, comment.dup
584+
break unless container.kind_of?(RDoc::Context)
585+
container.set_current_section param, comment.dup
585586
comment.text = ''
586587
break
587588
end
@@ -1290,6 +1291,7 @@ def parse_meta_method_params container, single, meth, tk, comment # :nodoc:
12901291
token_listener meth do
12911292
meth.params = ''
12921293

1294+
look_for_directives_in meth, comment
12931295
comment.normalize
12941296
comment.extract_call_seq meth
12951297

@@ -1336,6 +1338,7 @@ def parse_method(container, single, tk, comment)
13361338
return unless name
13371339

13381340
meth = RDoc::AnyMethod.new get_tkread, name
1341+
look_for_directives_in meth, comment
13391342
meth.singleton = single == SINGLE ? true : singleton
13401343

13411344
record_location meth

test/test_rdoc_parser_ruby.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,28 @@ def test_parse_redefinable_methods
17621762
end
17631763
end
17641764

1765+
def test_parse_method_with_args_directive
1766+
util_parser <<-RUBY
1767+
class C
1768+
def meth_with_args_after # :args: a, b, c
1769+
end
1770+
1771+
##
1772+
# :args: d, e, f
1773+
def meth_with_args_before
1774+
end
1775+
RUBY
1776+
1777+
@parser.scan
1778+
1779+
c = @store.find_class_named 'C'
1780+
1781+
assert_equal 'C#meth_with_args_after', c.method_list[0].full_name
1782+
assert_equal 'a, b, c', c.method_list[0].params
1783+
assert_equal 'C#meth_with_args_before', c.method_list[1].full_name
1784+
assert_equal 'd, e, f', c.method_list[1].params
1785+
end
1786+
17651787
def test_parse_method_bracket
17661788
util_parser <<-RUBY
17671789
class C

0 commit comments

Comments
 (0)