From 101b457bee1573ec1047efa4963f8fd50a5bb9ea Mon Sep 17 00:00:00 2001 From: Walter Smith Date: Wed, 9 Jan 2019 12:10:08 -0800 Subject: [PATCH] Clarify when to use if-case returns --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ae40c297d..f0ba682d5 100644 --- a/README.md +++ b/README.md @@ -1090,8 +1090,9 @@ Translations of the guide are available in the following languages: ``` * - Favor the ternary operator(`?:`) over `if/then/else/end` constructs. - It's more common and obviously more concise. + Favor the ternary operator(`?:`) over `if/then/else/end` constructs + for simple expressions. It's more common and obviously more + concise. [[link](#ternary-operator)] ```ruby @@ -1134,8 +1135,10 @@ Translations of the guide are available in the following languages: ``` * - Leverage the fact that `if` and `case` are expressions which return a - result. + When assigning a value that depends on a conditional, when + the value expressions are too long to use a ternary expression, + leverage the fact that `if` and `case` are expressions which + return a result. [[link](#use-if-case-returns)] ```ruby @@ -1147,11 +1150,13 @@ Translations of the guide are available in the following languages: end # good + result = condition ? x : y + result = if condition - x + complex.expression() else - y + too.long(to: fit.in(a, ternary)) end ```