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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user