summaryrefslogtreecommitdiffhomepage
path: root/ruby.html.markdown
diff options
context:
space:
mode:
authorIlya Vorontsov <vorontsov.i.e@gmail.com>2019-09-05 11:06:51 +0300
committerIlya Vorontsov <vorontsov.i.e@gmail.com>2019-09-05 11:06:51 +0300
commit4a14d54eb520f9776710102bfec740467b549745 (patch)
tree0b2bf822e0625d4ea483489fdb2b4d55cd81341f /ruby.html.markdown
parentffb9c5f909d860a98d3d86ed49bc169413e0dd65 (diff)
[ruby/ru] [ruby/en] added notes about postfix-if and about
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`.