Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

one-line case/when #37

Closed
burke opened this issue Sep 19, 2011 · 1 comment
Closed

one-line case/when #37

burke opened this issue Sep 19, 2011 · 1 comment

Comments

@burke
Copy link

burke commented Sep 19, 2011

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.

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 22, 2011

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.

@bbatsov bbatsov closed this as completed Sep 25, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants