Created
January 27, 2011 19:26
-
-
Save nahurst/799047 to your computer and use it in GitHub Desktop.
Ruby and/or vs &&/||
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
# "and" and && are not synonymous in Ruby | |
# "and" and "or" have a much lower precedence | |
# "and" and "or" are more like control flow operators than boolean operators | |
do_this() or raise "Failure" | |
assign_me = 10 and assign_me / 2 # (assign_me = 10) and assign_me / 2 ... => 5 | |
#vs | |
assign_me = 10 && assign_me / 2 # assign_me = (10 && assign_me) / 2 ... => undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment