Skip to content

Commit 9573575

Browse files
committed
proper handling for explicit block arguments in any_method#param_list, any_method#param_list fix for empty arguments list with non-empty yield parameters
1 parent 06b3f6a commit 9573575

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/rdoc/any_method.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,15 @@ def param_list
240240
return []
241241
end
242242

243-
params = params.gsub(/\s+/, '').split ','
243+
if @block_params then
244+
# If this method has explicit block parameters, remove any explicit
245+
# &block
246+
params.sub!(/,?\s*&\w+/, '')
247+
else
248+
params.sub!(/\&(\w+)/, '\1')
249+
end
250+
251+
params = params.gsub(/\s+/, '').split(',').reject(&:empty?)
244252

245253
params.map { |param| param.sub(/=.*/, '') }
246254
end

test/test_rdoc_any_method.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,35 @@ def test_param_list_params_block_params
334334
assert_equal %w[a b c d], m.param_list
335335
end
336336

337+
def test_param_list_empty_params_with_block
338+
m = RDoc::AnyMethod.new nil, 'method'
339+
m.parent = @c1
340+
341+
m.params = '()'
342+
m.block_params = 'a, b'
343+
344+
assert_equal %w[a b], m.param_list
345+
end
346+
347+
def test_param_list_ampersand_param_block_params
348+
m = RDoc::AnyMethod.new nil, 'method'
349+
m.parent = @c1
350+
351+
m.params = '(a, b, &block)'
352+
m.block_params = 'c, d'
353+
354+
assert_equal %w[a b c d], m.param_list
355+
end
356+
357+
def test_param_list_ampersand_param
358+
m = RDoc::AnyMethod.new nil, 'method'
359+
m.parent = @c1
360+
361+
m.params = '(a, b, &block)'
362+
363+
assert_equal %w[a b block], m.param_list
364+
end
365+
337366
def test_param_seq
338367
m = RDoc::AnyMethod.new nil, 'method'
339368
m.parent = @c1

0 commit comments

Comments
 (0)