DEV Community

Discussion on: Avoid nil propagation

Collapse
 
cghan profile image
Carlos Ghan

Nice topic, @delbetu !

In the ActiveRecord example, you can also use ActiveRecord::Base#none as null-object pattern and remove the early return:

user = User.find_by(id: params[:person_id]) || User.none
EmailSender.invite(user)
Enter fullscreen mode Exit fullscreen mode

My personal preference is to avoid (if possible) guard clauses and assertions since those make it harder to read and reason about the code, but I agree that sometimes it's not feasible.

Collapse
 
delbetu profile image
M Bellucci

oh, that is cool, I didn't know about ActiveRecord::Base#none
Thank you!