Why does single `=` work in `if` statement?

后端 未结 4 1231
囚心锁ツ
囚心锁ツ 2021-01-18 02:28

This code is provided as an example in for use with devise and OmniAuth, it works in my project.

class User < ActiveRecord::Base
  def self.new_with_sessi         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 03:29

    A assignment operator (=) returns the assigned value, which is then evaluated by the if. In ruby, only false and nil are considered as false. Everything else evaluates to true in a boolean context (like an if).

提交回复
热议问题