title: How do you assign a variable with the result of a if..else block?
body: <p>I had an argument with a colleague about the best way to assign a variable in an if..else block. His orignal code was :</p>
  
  <pre><code>@products = if params[:category]
    Category.find(params[:category]).products
  else
    Product.all
  end
  </code></pre>
  
  <p>I rewrote it this way :</p>
  
  <pre><code>if params[:category]
    @products = Category.find(params[:category]).products
  else
    @products = Product.all
  end
  </code></pre>
  
  <p>This could also be rewritten with a one-liner using a ternery operator (? :) but let's pretend that product assignment was longer than a 100 character and couldn't fit in one line.</p>
  
  <p>Which of the two is clearer to you? The first solution takes a little less space but I thought that declaring a variable and assigning it three lines after can be more error prone. I also like to see my <code>if</code> and <code>else</code> aligned, makes it easier for my brain to parse it!</p>