Skip to content

Commit f230f2e

Browse files
committed
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.
1 parent ade4222 commit f230f2e

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)