ruby-style-guide icon indicating copy to clipboard operation
ruby-style-guide copied to clipboard

A clarification regarding the use of when / then

Open AlexVPopov opened this issue 11 years ago • 4 comments

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

?

AlexVPopov avatar Feb 10 '14 14:02 AlexVPopov

I personally never mix one-liners and multi-liners. I feel that the visual consistency is important.

nixpulvis avatar Feb 10 '14 14:02 nixpulvis

I usually mix them, but I'm curious about other opinions.

fuadsaud avatar Feb 11 '14 02:02 fuadsaud

Interesting question! I'm not sure what I actually do in practice, but I think I usually don't mix them. :-) We should probably add some rule on the subject.

bbatsov avatar Jun 12 '19 07:06 bbatsov

😄 5 years later, I can say - I don't mix them :)

AlexVPopov avatar Jun 12 '19 08:06 AlexVPopov