summaryrefslogtreecommitdiffhomepage
path: root/ruby.html.markdown
diff options
context:
space:
mode:
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`.