Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If-else vs case #764

Closed
tejasbubane opened this issue Jun 20, 2019 · 1 comment · Fixed by #766
Closed

If-else vs case #764

tejasbubane opened this issue Jun 20, 2019 · 1 comment · Fixed by #766

Comments

@tejasbubane
Copy link
Contributor

This came up in a PR discussion: rubocop/rubocop#7153 (comment)

Suggestion is to prefer case over if-elsif-...-else

# bad
if arg == :foo
  foo_action
elsif arg == :bar
  bar_action
elsif arg == :baz
  baz_action
else
  final_action
end

# good
case arg
when :foo
  foo_action
when :bar
  bar_action
when :baz
  baz_action
else
  final_action
end
@bbatsov
Copy link
Collaborator

bbatsov commented Jun 20, 2019

I thought we had this already. After all it's one of the primary usecases of case, so it makes sense to recommend it.

tejasbubane added a commit to tejasbubane/ruby-style-guide that referenced this issue Jun 20, 2019
tejasbubane added a commit to tejasbubane/ruby-style-guide that referenced this issue Jul 8, 2019
bbatsov pushed a commit that referenced this issue Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants