title: checking existence of a ruby object and testing attributes of that object in one line
body: <p>Kind of a newbie question here but I promise it is really hard to google for. What I want to do is test the attribute of an object and test the existence of that same object in one line. I could do this:</p>
  
  <pre><code>user = User.find_by_id(user_id)
  if user
    if user.access_token == params[:access_token]
      puts "success"
    else
      puts "failure"
    end
  else
    puts "failure"
  end
  </code></pre>
  
  <p>I would like to seriously re-factor this and get rid of the nested if statements. Thing is, I can't do something like</p>
  
  <pre><code>if user &amp;&amp; user.access_token
  </code></pre>
  
  <p>since in the case where user is actually nil, Ruby will throw an error when trying to evaluate nil.access_token. Anybody know the actual correct way to re-factor this into one line? Is it even possible, or are the nested if statements the only way?</p>