rubocopでUse the return of the conditional for variable assignment and comparison.
のエラーが出た時の対処法。
環境
- rubocop 1.30.0
- Ruby 3.1.0
エラー内容
Use the return of the conditional for variable assignment and comparison.
変数の代入と比較には、条件式の戻り値を使用してください。
エラー対処法
# bad if foo bar = 1 else bar = 2 end # good bar = if foo 1 else 2 end
- Class: RuboCop::Cop::Style::ConditionalAssignment — Documentation for bbatsov/RuboCop (master)
- GitHub - rubocop/ruby-style-guide: A community-driven Ruby coding style guide
- Ruby: Use the return of the conditional for variable assignment and comparison - Stack Overflow
- 【Rubocop】Use the return of the conditional for variable assignment and comparison.エラーの対処法 - 紙一重の積み重ね