You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use when x then ... for one-line cases. The alternative syntax when x; ... is deprecated in Ruby 1.9.
This is actually not true. The syntax that was deprecated was when x: ..., with a colon, to avoid collision with the new hash literal syntax (eg: when key: value then :result)
I prefer to use when x; ..., since horizontal space is at a premium, especially when assigning the result to variable. The then is also kind of line-noise-y too, as it's implied by the presence of a when.
Anyway, I'm not against suggesting use of then for one-liners, but when x; ... is not deprecated, and should maybe be the suggested method. Discuss?
EDIT:
Never use if x; ... - it is deprecated in Ruby 1.9. Use the ternary operator instead.
This is also inaccurate. Bad for other reasons, but not deprecated.
The text was updated successfully, but these errors were encountered:
You're right of course. A double typo on my part. I don't like multiple statements on the same line separated with ; so I'm against recommending when x; ... I feel that the readability loss outweighs the gain of a few characters.
This is actually not true. The syntax that was deprecated was
when x: ...
, with a colon, to avoid collision with the new hash literal syntax (eg:when key: value then :result
)I prefer to use
when x; ...
, since horizontal space is at a premium, especially when assigning the result to variable. Thethen
is also kind of line-noise-y too, as it's implied by the presence of awhen
.Anyway, I'm not against suggesting use of
then
for one-liners, butwhen x; ...
is not deprecated, and should maybe be the suggested method. Discuss?EDIT:
This is also inaccurate. Bad for other reasons, but not deprecated.
The text was updated successfully, but these errors were encountered: