Simplify your Ruby code with the Robustness Principle
current_user method returns a
User, except when there is no user and it returns
nil. A search method returns an Array of results, unless there’s only one result, and it returns just that result instead. Seems reasonable, right? Maybe even convenient! But soon, these decisions will bury your code under a mountain of
if statements. There is a way to prevent this, though, and all it takes is a little thoughtfulness.