gpt4 book ai didi

ruby-on-rails - 为什么 ||和/或在 rails 中表现不同?

转载 作者:数据小太阳 更新时间:2023-10-29 07:42:52 26 4
gpt4 key购买 nike

<分区>

Possible Duplicates:
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 中的 相同?

案例 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])

将在 script/console 中生成以下 SQL:

 SELECT * FROM `events` WHERE (year = NULL)

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com