Feature #10343
Updated by sawa (Tsuyoshi Sawada) almost 2 years ago
In a `case` statement, statements, the condition part in the branches do are not have the same length always uniform in general, length, and especially, `else` is much shorter than the conditions (`when ...`). So when short. When we write the condition and the return value want to put each `when` statement in a single line, they are not always aligned, and are hard to read. ```ruby ~~~ruby case foo when some_very_long_condition then "a" when short_cond then "bb" when some_long_condition then "ccc" else "dddd" end ``` ~~~ I propose to allow think it would be better if we can do postfix notations with `when` and `else` (or `otherwise`) inside `case` statement as below: below. ```ruby ~~~ruby case foo "a" when some_very_long_proc "bb" when short_regex "ccc" when some_long_regex "dddd" else end ``` ~~~ Pros are: 1) Postfix notation does not require `then` or `;`, so it is concise. 2) The return values from the branches (e.g., length of `"a"`, `"bb"`, `"ccc"`, `"dddd"`) tend `"dddd"`, etc. can also vary, but they are usually more homogenuous with respect to be shorter and more uniformly lengthened length than the conditions, hence they are somewhat close to being aligned naturally, making this condition, and easier to read. 3) We align. And, it is these values that we are usually more interested in the return values in, rather than the conditions. 4) This conditional parts. Furthermore, this notation is closer to the case-like conditional notations regularly notation standardly used in mathematics: ``` x! = 1 (x = 0) x (x - 1)! (otherwise) ``` So mathematics for conditions, so it would be easier to read for those who are familiar with mathematics. ~~~ x! = 1 (x = 0) x (x - 1)! (otherwise) ~~~