Today I Learned

hashrocket A Hashrocket project

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/

See More #ruby TILs
Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.