ruby-style-guide
ruby-style-guide copied to clipboard
Ternary branch text seems too strong
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.
Not intended. The point was avoid sequential expressions (e.g. foo; bar). The language should definitely be improved here.