Pattern: Missing use of explicit block argument
Issue: -
This rule enforces the use of explicit block argument to avoid writing block literal that just passes its arguments to another block.
# bad
def with_tmp_dir
Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) { |dir| yield dir } # block just passes arguments
end
end
# bad
def nine_times
9.times { yield }
end
# good
def with_tmp_dir(&block)
Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir, &block)
end
end
with_tmp_dir do |dir|
puts "dir is accessible as a parameter and pwd is set: #{dir}"
end
# good
def nine_times(&block)
9.times(&block)
end