前提
早期リターンを勉強しているのですが、早期リターン利点として「防御的プログラミングでの早期return」で使えるとあるのですが、内容の意味がいまいち分かりませんでした。
また参考として、下記のコードの早期リターンでの記述するとどのようになるのでしょうか?
[早期リターンURL]:
https://shinkufencer.hateblo.jp/entry/2020/12/05/000000
発生している問題・エラーメッセージ
def following?(other_user) self.followings.include?(other_user) end def follow(other_user) unless self == other_user self.relationships.find_or_create_by(follow_id: other_user.id) end end def unfollow(other_user) relationship = self.relationships.find_by(follow_id: other_user.id) if relationship relationship.destroy end end
試したこと
上記コードを早期リターンで直すとどう書けるのかをご教示頂ければ幸いです。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。