-
-
Save torokmark/8347c58f0cda918e99cb43fba84aea81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## eager or | |
puts false | nil # false | |
puts true | nil # true | |
puts 2 == 2 | 2 # true | |
puts 2 == 2 | 3 # false, here 3 is consider as an int value, not a logical value | |
## lazy or | |
puts 2 == 2 || 3 # 3 | |
puts 3 || 2 == 2 # true | |
puts 2 == 2 or 3 # 3 | |
puts 3 or 2 == 2 # true | |
## evaluation of only one side | |
a = 2 || b = 3 | |
puts "|| '#{ a }' '#{ b }'" # || '2' '' | |
a = 2 or b = 3 | |
puts "or '#{ a }' '#{ b }'" # or '2' '' | |
## evaluation of both sides | |
a = false || b = 3 | |
puts "|| '#{ a }' '#{ b }'" # || '3' '3' | |
a = false or b = 3 | |
puts "or '#{ a }' '#{ b }'" # or 'false' '3' | |
## a and b are both 3 | |
a = (false || b = 3) | |
a = ( b = 3 ) | |
a = 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment