diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | doc/syntax/control_expressions.rdoc | 21 |
2 files changed, 25 insertions, 0 deletions
@@ -1,3 +1,7 @@ +Thu Jan 17 09:08:37 2013 Eric Hodel <drbrain@segment7.net> + + * doc/syntax/control_expressions.rdoc: Added ? : ternary if + Thu Jan 17 08:36:04 2013 Eric Hodel <drbrain@segment7.net> * doc/syntax/miscellaneous.rdoc: Added documentation for alias, undef, diff --git a/doc/syntax/control_expressions.rdoc b/doc/syntax/control_expressions.rdoc index e3fc19d72d..0efc1668ad 100644 --- a/doc/syntax/control_expressions.rdoc +++ b/doc/syntax/control_expressions.rdoc @@ -86,6 +86,27 @@ side-effect is to cache a value into a local variable: The result value of an +if+ expression is the last value executed in the expression. +== Ternary if + +You may also write a if-then-else expression using <code>?</code> and +<code>:</code>. This ternary if: + + input_type = gets =~ /hello/i ? "greeting" : "other" + +Is the same as this +if+ expression: + + input_type = + if gets =~ /hello/i + "greeting" + else + "other" + end + +While the ternary if is much shorter to write than the more verbose form, for +readability it is recommended that the ternary if is only used for simple +conditionals. Also, avoid using multiple ternary conditions in the same +expression as this can be confusing. + == +unless+ Expression The +unless+ expression is the opposite of the +if+ expression. If the value |