Skip to content

Latest commit

 

History

History
34 lines (26 loc) · 545 Bytes

Style-CaseLikeIf.md

File metadata and controls

34 lines (26 loc) · 545 Bytes

Pattern: Missing use of case-when

Issue: -

Description

Identifies places where if-elsif constructions can be replaced with case-when.

Examples

# bad
if status == :active
  perform_action
elsif status == :inactive || status == :hibernating
  check_timeout
else
  final_action
end

# good
case status
when :active
  perform_action
when :inactive, :hibernating
  check_timeout
else
  final_action
end

Further Reading