2010-07-12 51 views
0

可能重複:
Is there any wisdom behind 「and」, 「or」 operators in Ruby ?紅寶石邏輯運算符

的區別是什麼,如果有的話,以下對邏輯運算符之間?

  1. & &與和
  2. ||與或
+4

涵蓋在一些問題中,包括[在Ruby中是否有任何智慧behide「和」,「或」運算符?](http://stackoverflow.com/questions/1434842/is-there-any-wisdom-behide-和 - 或 - 運算符在紅寶石),[紅寶石:||之間的差異和'or'](http://stackoverflow.com/questions/2083112/ruby-difference-between-and-or),[在Ruby和Ruby之間的差異?](http://stackoverflow.com/問題/ 1426826 /差之間和 - 和功能於紅寶石)。總之,優先。 – 2010-07-12 03:04:21

回答

8

「單詞」版本的優先級低於「符號」版本。事實上,他們的優先級比分配還要低。

+0

這可以解釋爲什麼'@user = User.find_by_id('[email protected]')或者User.find_by_email('[email protected]')'將'@ user'設置爲nil,即使記錄存在。 – Chloe 2017-08-13 18:15:27