露比运算符(a/k/a双爆炸) [英] Ruby, !! operator (a/k/a the double-bang)
本文介绍了露比运算符(a/k/a双爆炸)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
是什么!是指红宝石?
Possible Duplicate:
What does !! mean in ruby?
我是Ruby的新手,在任何地方都找不到关于"!!"的描述.方法.
I'm new to Ruby and can't find anywhere description of what "!!" means.
这是一个例子:
def signed_in?
!!current_user
end
如果这是双重否定,为什么不说:
If this is a double negative, why not to say:
def signed_in?
current_user
end
请帮助.
推荐答案
在大多数编程语言(包括Ruby)中,!
将返回与操作数的布尔值相反的值.因此,当您将两个感叹号链接在一起时,它会将值转换为布尔值.
In most programming languages, including Ruby, !
will return the opposite of the boolean value of the operand. So when you chain two exclamation marks together, it converts the value to a boolean.
这篇关于露比运算符(a/k/a双爆炸)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文