Skip to content

Instantly share code, notes, and snippets.

@nahurst
Created January 27, 2011 19:26
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 nahurst/799047 to your computer and use it in GitHub Desktop.
Save nahurst/799047 to your computer and use it in GitHub Desktop.
Ruby and/or vs &&/||
# "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