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

Ternary branch text seems too strong

Open pochmann opened this issue 7 years ago • 1 comments

It says:

Use one expression per branch in a ternary operator. This also means that ternary operators must not be nested.

So apparently you're counting subexpressions and thus these are considered bad:

i ? t + 1 : e          # Three expressions in true-branch: t, 1 and t + 1

i ? f(t) : e           # Two expressions in true-branch: t and f(t)

x < 0 ? -x : x         # Two expressions in true-branch: x and -x

Is that really intended? If so, I think it would be good to include them as "bad" examples. If not, then I think the wording should be improved.

pochmann avatar Dec 03 '17 17:12 pochmann

Not intended. The point was avoid sequential expressions (e.g. foo; bar). The language should definitely be improved here.

bbatsov avatar Jun 12 '19 09:06 bbatsov