From f230f2e1cbced77abeec7ad1c6cc54ffaf722ac2 Mon Sep 17 00:00:00 2001 From: Ernane Ferreira Date: Tue, 14 Jul 2026 00:24:58 -0300 Subject: [PATCH] Fix Ruby 4.0 warning: default before_template/after_template now accept a block The call site in SGML#call passes a block to both methods via `&block`, but the default no-op implementations had no block parameter. Ruby 4.0 warns about this ("block passed to method may be ignored"). Adding `(&)` to both signatures silently accepts the block without using it. --- lib/phlex/sgml.rb | 4 ++-- quickdraw/sgml/callbacks.test.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/phlex/sgml.rb b/lib/phlex/sgml.rb index 45040b22..31100e70 100644 --- a/lib/phlex/sgml.rb +++ b/lib/phlex/sgml.rb @@ -326,11 +326,11 @@ def json_escape(string) nil end - private def before_template + private def before_template(&) nil end - private def after_template + private def after_template(&) nil end diff --git a/quickdraw/sgml/callbacks.test.rb b/quickdraw/sgml/callbacks.test.rb index 490e3944..38747d3f 100644 --- a/quickdraw/sgml/callbacks.test.rb +++ b/quickdraw/sgml/callbacks.test.rb @@ -30,4 +30,9 @@ def view_template test "callbacks are called in the correct order" do assert_equal Example.call, "1234567" end + + test "default before_template and after_template accept a block" do + klass = Class.new(Phlex::HTML) { def view_template = span { "hello" } } + assert_equal klass.call { "ignored" }, "hello" + end end