Skip to content

Commit 6cf883a

Browse files
committed
Fix unused block warnings for template methods
Ref: https://bugs.ruby-lang.org/issues/15554 Ruby 3.4 now warns when passing a block to a method that never expects one. In the case of rendered template, a block is always passed for some engines that do expect one, but some never expect it. We can silence that warning by declaring an anonymous block.
1 parent e90cb82 commit 6cf883a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

actionview/lib/action_view/template.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,13 @@ def compiled_source
438438

439439
method_arguments =
440440
if set_strict_locals
441-
"output_buffer, #{set_strict_locals}"
441+
if set_strict_locals.include?("&")
442+
"output_buffer, #{set_strict_locals}"
443+
else
444+
"output_buffer, #{set_strict_locals}, &_"
445+
end
442446
else
443-
"local_assigns, output_buffer"
447+
"local_assigns, output_buffer, &_"
444448
end
445449

446450
# Make sure that the resulting String to be eval'd is in the
@@ -505,6 +509,8 @@ def compile(mod)
505509
![:keyreq, :key, :keyrest, :nokey].include?(parameter[0])
506510
end
507511

512+
non_kwarg_parameters.pop if non_kwarg_parameters.last == %i(block _)
513+
508514
unless non_kwarg_parameters.empty?
509515
mod.undef_method(method_name)
510516

0 commit comments

Comments
 (0)