Ruby 3.4 Warn on Method Unused Blocks
A change to Ruby 3.4 will print a warning while using the verbose flag -w
when a method is passed a block and the block is not used by that method.
Here's our example file scratch.rb
-
def print_message(message) = puts message
print_message("hello_world") { puts "hello anonymous" }
> ruby scratch.rb
hello world
> ruby -w scratch.rb
scratch.rb:3: warning: the block passed to 'Object#print_message' defined at scratch.rb:1 may be ignored
hello world
https://www.ruby-lang.org/en/news/2024/12/25/ruby-3-4-0-released/
Tweet