summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2015-03-04 23:39:55 -0600
committerLevi Bostian <levi.bostian@gmail.com>2015-03-04 23:39:55 -0600
commit303ec58a52cef60d8fdc13babe378f4a2e6117c3 (patch)
tree7ca5812542ac3fd1e77dd18069e01a93be2f6de1
parent8a43f93d587a7bce1fd58f0587653cfca5df1d85 (diff)
parent081deac4b189f9fc4beced619653a2d602fd3b7a (diff)
Merge pull request #987 from geoffliu/master
[Ruby/en] Add logical operators to Ruby tutorial
-rw-r--r--ruby.html.markdown17
1 files changed, 13 insertions, 4 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown
index 7cf5bdc7..1883d1ad 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -60,8 +60,6 @@ false.class #=> FalseClass
# Inequality
1 != 1 #=> false
2 != 1 #=> true
-!true #=> false
-!false #=> true
# apart from false itself, nil is the only other 'falsey' value
@@ -75,6 +73,17 @@ false.class #=> FalseClass
2 <= 2 #=> true
2 >= 2 #=> true
+# Logical operators
+true && false #=> false
+true || false #=> true
+!true #=> false
+
+# Alternate spellings of logical operators
+true and false #=> false
+true or false #=> true
+not true #=> false
+
+
# Strings are objects
'I am a string'.class #=> String
@@ -280,9 +289,9 @@ rescue NoMemoryError => exception_variable
puts 'NoMemoryError was raised', exception_variable
rescue RuntimeError => other_exception_variable
puts 'RuntimeError was raised now'
-else
+else
puts 'This runs if no exceptions were thrown at all'
-ensure
+ensure
puts 'This code always runs no matter what'
end