mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-11-29 22:12:07 +03:00
Merge pull request #987 from geoffliu/master
[Ruby/en] Add logical operators to Ruby tutorial
This commit is contained in:
commit
303ec58a52
@ -60,8 +60,6 @@ false.class #=> FalseClass
|
|||||||
# Inequality
|
# Inequality
|
||||||
1 != 1 #=> false
|
1 != 1 #=> false
|
||||||
2 != 1 #=> true
|
2 != 1 #=> true
|
||||||
!true #=> false
|
|
||||||
!false #=> true
|
|
||||||
|
|
||||||
# apart from false itself, nil is the only other 'falsey' value
|
# apart from false itself, nil is the only other 'falsey' value
|
||||||
|
|
||||||
@ -75,6 +73,17 @@ false.class #=> FalseClass
|
|||||||
2 <= 2 #=> true
|
2 <= 2 #=> true
|
||||||
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
|
# Strings are objects
|
||||||
|
|
||||||
'I am a string'.class #=> String
|
'I am a string'.class #=> String
|
||||||
@ -280,9 +289,9 @@ rescue NoMemoryError => exception_variable
|
|||||||
puts 'NoMemoryError was raised', exception_variable
|
puts 'NoMemoryError was raised', exception_variable
|
||||||
rescue RuntimeError => other_exception_variable
|
rescue RuntimeError => other_exception_variable
|
||||||
puts 'RuntimeError was raised now'
|
puts 'RuntimeError was raised now'
|
||||||
else
|
else
|
||||||
puts 'This runs if no exceptions were thrown at all'
|
puts 'This runs if no exceptions were thrown at all'
|
||||||
ensure
|
ensure
|
||||||
puts 'This code always runs no matter what'
|
puts 'This code always runs no matter what'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user