好吧,我是绿色的,但是下面的def似乎是双负的
def signed_in?
!current_user.nil? #the current user is not...um...not
end
Run Code Online (Sandbox Code Playgroud)
由于我的病人导师M.Hartl在他的Rails教程中使用它.我必须相信这是吱吱作响,但......
不会说"当前用户"更干净吗?
def signed_in?
current_user
current_user.present?
current_user.any?
!!current_user
end
Run Code Online (Sandbox Code Playgroud)
爆炸有什么好处?
current_user | nil | false | true | "" | [] | [nil] | [0]
-----------------------------------------------------------------------------------
current_user | nil | false | true | "" | [] | [nil] | [0]
!current_user.nil? | false | true | true | true | true | true | true
!!current_user | false | false | true | true | true | true | true
current_user.present? | false | false | true | false | false | true | true
current_user.any? | error | error | error | error | false | false | true
Run Code Online (Sandbox Code Playgroud)