rubocop / rubocop/ruby-style-guide

A clarification regarding the use of when / then

Open
#280 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

New Rule
Dominant language
No language data
Stars
16.5k
Forks
3.3k
PR merge metrics
No merged PRs in 30d

Description

In a case statement with several when clauses, if most of the when clauses are short enough to be written in the when/then form, but one or two are longer and must be written in the form:

when foo
  bar...

should all whens be written in the second form or is it acceptable to have both oneliners and multiliners, like:

case x
when a then b
when c
  # do something
else
  # do something else
end

?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the guide section covering Ruby case statements and compare its existing when/then guidance with the examples in this issue. Done means the guide explicitly states whether mixing one-line and multiline when clauses is acceptable, with a consistent example and any needed rationale.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.