LoginSignup
3
2

More than 3 years have passed since last update.

rubocopに追加された Style/HashLikeCase Consider replacing case-when with a hash lookup

Last updated at Posted at 2020-07-21

rubocopに追加された Style/HashLikeCase

case文で記述しなくても良い場合は配列で定義してしまいましょうというルール。

rubocop 0.88.0 で追加、非常に良いですね。

悪い例
type = 'test'
case type
when 'interview'
  'インタビュー'
when 'test'
  'テスト'
when 'standard'
  '通常'
end
良い例
TITLES = {
  'interview' => 'インタビュー',
  'test' => 'テスト',
  'standard' => '通常',
}

type = 'test'
TITLES[type]

公式リポジトリの情報

issueと経緯

PRと実装

3
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2