I am wondering if there is a way in Ruby to write a one-line if-then-else statement using words as operators, in a manner similar to python's
a if b else c
I am aware of the classic ternary conditional, but I have the feeling Ruby is more of a "wordsey" language than a "symboley" language, so I am trying to better encapsulate the spirit of the language.
I also am aware of this method,
if a then b else c end
which is basically squishing a multi-liner onto one line, but the end
at the end of the line feels cumbersome and redundant. I think the ternary conditional would be preferable to this.
So for you who know Ruby well, is there a better way to write this? If not, which of the methods is the most Rubyesque?
The following questions are not addressed by the linked post:
- Is there a cleaner way than
if a then b else c end
to write a "wordsey" one-line if-then-else in Ruby? - Is the ternary conditional or the wordsey version more appropriate for the Ruby paradigm?