【问题标题】:Ruby logical operators [duplicate]Ruby逻辑运算符[重复] 【发布时间】:2011-03-14 15:03:54 【问题描述】: 可能重复:Is there any wisdom behind “and”, “or” operators in Ruby ? 以下逻辑运算符对之间有什么区别(如果有)? && 与和 ||与或 【问题讨论】: 涉及多个问题,包括Is there any wisdom behide "and", "or" operator in Ruby ?、Ruby: difference between || and ‘or’、Difference between “and” and && in Ruby?。简而言之,优先级。 标签: ruby logical-operators 【解决方案1】: “word”版本的优先级低于“symbol”版本。事实上,它们的优先级甚至低于赋值。 【讨论】: 这可以解释为什么 @user = User.find_by_id('test2@example.com') or User.find_by_email('test2@example.com') 将 @user 设置为 nil,即使记录存在。