Skip to content

Files

Latest commit

 

History

History
33 lines (25 loc) · 641 Bytes

Style-HashLikeCase.md

File metadata and controls

33 lines (25 loc) · 641 Bytes

Pattern: Use of case-when instead of hash lookup

Issue: -

Description

Checks for places where case-when represents a simple 1:1 mapping and can be replaced with a hash lookup.

Examples

# bad
case country
when 'europe'
  'http://eu.example.com'
when 'america'
  'http://us.example.com'
when 'australia'
  'http://au.example.com'
end

# good
SITES = {
  'europe'    => 'http://eu.example.com',
  'america'   => 'http://us.example.com',
  'australia' => 'http://au.example.com'
}
SITES[country]

Further Reading