Choosing between if and a modifier
A little bit of bikeshedding: In Ruby, even outside of guard clauses, I sometimes use modifiers to make the code easier to read out loud.
A mental rule that I use to choose when to use a full if
versus a
modifier is taking into consideration if the condition has a side
effect:
In this case I would choose the explicit if
because the post.save
has some important information when reading this code, while return
Success(post) if post.save
focuses on what is returned when skimming
the code.