DEV Community

Discussion on: I've never become overly convinced that switch statements are that much cleaner than `if else if else if else if else`

Collapse
 
andrewbrown profile image
Andrew Brown 🇨🇦

In ruby case statements feel less verbose, less prone to error since the intention is to validate a single statement against multiple outcomes and is more human readable.

With linting case statements are one way to still have compact code.

Everything has its utility.

if    status == :active     { '/active'}
elsif status == :incomplete { '/incomplete'}
elsif status == :suspended  { '/suspended'}
end

case status
when :active     then '/active'
when :incomplete then '/incomplete'
when :suspended  then '/suspended'
end
Enter fullscreen mode Exit fullscreen mode