SCUEL開発者ブログ

医療機関および介護事業所などのデータベース事業『SCUEL』を作っているエンジニア達のブログです。エンジニア募集中です!ご興味がありましたら、以下のフォームからお問い合わせください。 http://goo.gl/forms/8fPwBHDL2H

"Unused block argument - `%s`. If it's necessary, use `_` or `_%s` as an argument name to indicate that it won't be used."の対処方法

Rubocopで、以下のような警告が出た場合の対処方法。

Unused block argument - `%s`. If it's necessary, use `_` or `_%s` as an argument name to indicate that it won't be used.

%sには、ブロック内で使われていないアーギュメントが入ります。


ブロック内で利用しないアーギュメントの頭にアンダースコアを付けることで解決します。

Class: RuboCop::Cop::Lint::UnusedBlockArgument — Documentation for rubocop (0.39.0)

@bad
do_something do |used, unused|
  puts used
end

@good
do_something do |used, _unused|
  puts used
end