Skip to content

Commit f1c7f11

Browse files
authored
Fix Ruby 4.0 warning in default before_template and after_template (#986)
Fixes #985 `SGML#call` passes the caller's block to `before_template` and `after_template` via `&block`, but the default no-op implementations had no block parameter. Ruby 4.0 warns about this: ``` warning: the block passed to 'before_template' may be ignored warning: the block passed to 'after_template' may be ignored ``` I added `(&)` to both signatures so they accept the block without binding it to a variable. Subclasses that override these methods won't be affected.
2 parents ade4222 + f230f2e commit f1c7f11

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/phlex/sgml.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,11 @@ def json_escape(string)
326326
nil
327327
end
328328

329-
private def before_template
329+
private def before_template(&)
330330
nil
331331
end
332332

333-
private def after_template
333+
private def after_template(&)
334334
nil
335335
end
336336

quickdraw/sgml/callbacks.test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ def view_template
3030
test "callbacks are called in the correct order" do
3131
assert_equal Example.call, "<i>1</i><i>2</i><i>3</i><i>4</i><i>5</i><i>6</i><i>7</i>"
3232
end
33+
34+
test "default before_template and after_template accept a block" do
35+
klass = Class.new(Phlex::HTML) { def view_template = span { "hello" } }
36+
assert_equal klass.call { "ignored" }, "<span>hello</span>"
37+
end
3338
end

0 commit comments

Comments
 (0)