Skip to content

Instantly share code, notes, and snippets.

@torokmark
Last active August 19, 2019 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torokmark/8347c58f0cda918e99cb43fba84aea81 to your computer and use it in GitHub Desktop.
Save torokmark/8347c58f0cda918e99cb43fba84aea81 to your computer and use it in GitHub Desktop.
## 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