From 4a14d54eb520f9776710102bfec740467b549745 Mon Sep 17 00:00:00 2001 From: Ilya Vorontsov Date: Thu, 5 Sep 2019 11:06:51 +0300 Subject: [ruby/ru] [ruby/en] added notes about postfix-if and about --- ruby.html.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 2595d1d5..d77672ab 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -247,6 +247,14 @@ else 'else, also optional' end +# If a condition controls invokation of a single statement rather than a block of code +# you can use postfix-if notation +warnings = ['Patronimic is missing', 'Address too short'] +puts("Some warnings occurred:\n" + warnings.join("\n")) if !warnings.empty? + +# Rephrase condition if `unless` sounds better than `if` +puts("Some warnings occurred:\n" + warnings.join("\n")) unless warnings.empty? + # Loops # In Ruby, traditional `for` loops aren't very common. Instead, these # basic loops are implemented using enumerable, which hinges on `each`. -- cgit v1.2.3