Ruby:为什么 `puts true and false` return 为真?

Ruby: why does `puts true and false` return true?

在 Ruby 中,我刚刚注意到:

这种行为背后的 logic/reason 是什么?

因为 puts 绑定比 and 强:你的代码等于

(puts true) and false
true
#=> nil

您可以检查运算符 precedence in docs

要获得您可以使用 && 的内容,它的优先级高于 and:

puts true && false
false
#=> nil