逻辑运算符(&& || and or)
a = true b = false c = a and b puts c #true 比较特殊,加括号后为false #优先级:(puts true) and false
#and or 的优先级最低,比 = 低
a = true b = false c = a or b puts c #true a = true b = false c = a && b puts c #false a = true b = false c = a || b puts c #true puts "......................" a = true b = false c = (a and b) puts c #false a = true b = false c = (a or b) puts c #true a = true b = false c = (a && b ) puts c #false a = true b = false c = (a || b) puts c #true puts "....................." a = 1 b = 2 c = a and b #运算符优先级:(puts a) and b d = (a and b) puts c,d #1,2 a = 1 b = 2 c = a or b d = (a or b) puts c,d #1,1 #&&操作符先求解它们的第一个操作数,如果为false,那么返回它们的第一个操作数,否则,返回第二个操作数。 #||操作符先求解它们的第一个操作数,如果为true,那么返回它们的第一个操作数,否则,返回第二个操作数。 a = 1 b = 2 c = a && b d = (a && b) puts c,d #2,2 a = 1 b = 2 c = a || b d = (a || b) puts c,d #1,1