summaryrefslogtreecommitdiffhomepage
path: root/ruby.html.markdown
diff options
context:
space:
mode:
authorDivay Prakash <divayprakash@users.noreply.github.com>2019-09-17 19:27:44 +0530
committerGitHub <noreply@github.com>2019-09-17 19:27:44 +0530
commitc3cc7cc7b23a5306b3b3c27b7d56e99ee968f510 (patch)
treec75378e792a95bd8beb3ee5751fa461d59c65092 /ruby.html.markdown
parenta808656085b040c89a8a94677fb7e38f03a3e374 (diff)
parent4a14d54eb520f9776710102bfec740467b549745 (diff)
Merge pull request #3621 from VorontsovIE/ruby-postfix-if
[ruby/ru] [ruby/en] notes about postfix-if and `unless`
Diffstat (limited to 'ruby.html.markdown')
-rw-r--r--ruby.html.markdown8
1 files changed, 8 insertions, 0 deletions
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`.