Ruby: check if object is nil

前端 未结 3 979
轮回少年
轮回少年 2021-02-14 16:07
  def parse( line )
    _, remote_addr, status, request, size, referrer, http_user_agent, http_x_forwarded_for = /^([^\\s]+) - (\\d+) \\\"(.+)\\\" (\\d+) \\\"(.*)\\\" \\         


        
3条回答
  •  隐瞒了意图╮
    2021-02-14 16:40

    Ruby 2.3.0 added a safe navigation operator (&.) that checks for nil before calling a method.

    request&.split(' ')
    

    This is more or less semantically equivalent to

    !request.nil? && request.split(' ')
    

提交回复
热议问题