可能重複:
i = true and false in Ruby is true?
What is the difference between Perl's (or, and) and (||, &&) short-circuit operators?
Ruby: difference between || and 'or'爲什麼||和或在軌道中表現不同?
是||
相同的Rails or
?
例A:
@year = params[:year] || Time.now.year
Events.all(:conditions => ['year = ?', @year])
將產生script/console
以下SQL:
SELECT * FROM `events` WHERE (year = 2000)
情況B:
@year = params[:year] or Time.now.year
Events.all(:conditions => ['year = ?', @year])
將產生以下SQL中script/console
:
SELECT * FROM `events` WHERE (year = NULL)
同樣的問題[我=真和假的Ruby是真實的?](http://stackoverflow.com/questions/2802494/i-true-and-false-in-ruby-is-true)除了'或'而不是'和'。 – sepp2k 2010-10-11 09:17:17
複製到:http://stackoverflow.com/questions/3826112/in-ruby-should-we-always-use-instead-of-and-or-unless-for-specia/3828955#3828955,http:// stackoverflow.com/questions/1512547/what-is-the-difference-between-perls-or-and-and-short-circuit-op可能還有更多。 – draegtun 2010-10-11 10:08:48
此問題已在http://StackOverflow.Com/q/2083112/,http://StackOverflow.Com/q/1625946/,http://StackOverflow.Com/q/1426826/,http ://StackOverflow.Com/q/1840488/,http://StackOverflow.Com/q/1434842/,http://StackOverflow.Com/q/2376369/,http://StackOverflow.Com/q/2802494/ ,http://StackOverflow.Com/q/372652/。 – 2010-10-11 13:26:16