title: Ruby Conditional If Else Assignment
body: <p>So I have the following code that I wanted to make a little more readable:</p>
  
  <pre><code>user = User.find_by_username(username)
  user = User.new(credentials) if user.nil?
  </code></pre>
  
  <p>Essentially the first line is the default, the following line instantiates itself if it's not already set.</p>
  
  <p>Is there a way I can clean this up a bit and get it onto a single line of code? Something like this maybe:</p>
  
  <pre><code>user = User.find_by_username(username) || User.new(credentials)
  </code></pre>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>I now realize the the code I provided does exactly what I need, sorry for wasting cyberspace but feel free to suggest alternative solutions.</p>