Use respond_to? instead of try

Usually when we use `try` we actually mean `try!`, which is the same as
the safe navigation operator. However, there are a few cases where we
actually mean to execute a method if the object responds to that method.

In those cases using `try` would actually be OK, but in order to avoid
confusion as to whether we mean to check for `respond_to?` or we mean to
use safe navigation, I'm removing all usages of `try`.
This commit is contained in:
Javi Martín
2019-10-10 03:30:31 +02:00
parent 1004ac01f8
commit 38b7307450
3 changed files with 4 additions and 4 deletions

View File

@@ -120,7 +120,7 @@ class Comment < ApplicationRecord
end
def call_after_commented
commentable.try(:after_commented)
commentable.after_commented if commentable.respond_to?(:after_commented)
end
def self.body_max_length