Ruby on Rails中,如何将true、false或nil转换为长尾词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计456个文字,预计阅读时间需要2分钟。
我有boolean类型的变量var,字段::processing :type Boolean。在我面前的开发人员写了一些代码,说这个:processing=nil(出于某种原因,他将它设置为nil而不是false)。然后他做了这个if语句:return if。
我有一个boolean var的对象.field :processing, :type => Boolean
在我面前的开发人员写了一些代码说这个.
:processing => nil
(出于某种原因,他将其设置为nil而不是false.)
然后他做了这个if语句
return if self.processing dosomethingelse....
如果我编写代码来执行此操作
:processing => false
下次运行此代码时会发生什么? dosomethingelse运行吗?
return if self.processing dosomethingelse....
更新===========
对于下面的许多问题,我们将在此回答.
我加了这个
field :processing, :type => Boolean, :default => false
它打破了应用程序.当我改变到上面的dosomethingelse永远不会运行?
如果self.processing返回则返回.有什么建议?
更新2 =======================================
以下是对我的代码(编辑)中的处理的每个引用.如果重要的话,我也在使用MongoDB.
.where(:processing => nil).gt(:retries => 0).asc(:send_time).all.entries if self.processing end return if self.processing self.update_attributes(:processing => true) dosomethingelse.... .where(:sent_time => nil).where(:processing => nil).gt(:retries => 0).asc(:send_time).all.entries :processing => nil Ruby使用truthy和falsey.
虚假和零是假的,其他一切都是真实的.
if true puts "true is truthy, duh!" else puts "true is falsey, wtf!" end
输出是“真是真,真啊!”
if nil puts "nil is truthy" else puts "nil is falsey" end
输出是“零是假的”
if 0 puts "0 is truthy" else puts "0 is falsey" end
输出是“0是真的”
见这个解释True and False
本文共计456个文字,预计阅读时间需要2分钟。
我有boolean类型的变量var,字段::processing :type Boolean。在我面前的开发人员写了一些代码,说这个:processing=nil(出于某种原因,他将它设置为nil而不是false)。然后他做了这个if语句:return if。
我有一个boolean var的对象.field :processing, :type => Boolean
在我面前的开发人员写了一些代码说这个.
:processing => nil
(出于某种原因,他将其设置为nil而不是false.)
然后他做了这个if语句
return if self.processing dosomethingelse....
如果我编写代码来执行此操作
:processing => false
下次运行此代码时会发生什么? dosomethingelse运行吗?
return if self.processing dosomethingelse....
更新===========
对于下面的许多问题,我们将在此回答.
我加了这个
field :processing, :type => Boolean, :default => false
它打破了应用程序.当我改变到上面的dosomethingelse永远不会运行?
如果self.processing返回则返回.有什么建议?
更新2 =======================================
以下是对我的代码(编辑)中的处理的每个引用.如果重要的话,我也在使用MongoDB.
.where(:processing => nil).gt(:retries => 0).asc(:send_time).all.entries if self.processing end return if self.processing self.update_attributes(:processing => true) dosomethingelse.... .where(:sent_time => nil).where(:processing => nil).gt(:retries => 0).asc(:send_time).all.entries :processing => nil Ruby使用truthy和falsey.
虚假和零是假的,其他一切都是真实的.
if true puts "true is truthy, duh!" else puts "true is falsey, wtf!" end
输出是“真是真,真啊!”
if nil puts "nil is truthy" else puts "nil is falsey" end
输出是“零是假的”
if 0 puts "0 is truthy" else puts "0 is falsey" end
输出是“0是真的”
见这个解释True and False

