Created
May 8, 2010 10:14
-
-
Save hannestyden/394477 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
# Logical operator precedence in Ruby | |
# | |
# Problems might arise in combination with the assignment operator. | |
# | |
# http://blog.jayfields.com/2007/08/ruby-operator-precedence-of-and-which.html | |
# http://phrogz.net/ProgrammingRuby/language.html#table_18.4 | |
# Definitions: | |
# '&&' and '||' are logical operators | |
# 'and' and 'or' are logical composition operators | |
# | |
# '&&' compared to 'and' | |
# | |
a = true && false # => false | |
# \___________/ | |
a # => false | |
b = true and false # => false | |
# \______/ | |
b # => true (!) | |
c = (true and false) # => false | |
# \______________/ | |
c # => false | |
# | |
# '||' compared to 'or' | |
# | |
d = false || true # => true | |
# \___________/ | |
d # => true | |
e = false or true # => true | |
# \_______/ | |
e # => false (!) | |
f = (false or true) # => true | |
# \_____________/ | |
f # => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment