If without else

Is it good ruby to do the following

if current_user
  do something
end

I’ve typically have done:

if current_user
  do something
else
end

The other option is:

do something if current_user

However with a very long “do something” that gets uncluttered in a hurry.

What’s the best practice, assuming “do something” is multiline?

I never include the else if there isn’t something in that branch.

I use the first variant you showed.

We avoid the third because it’s easy to miss the if sometimes.

1 Like