diff options
author | Akira Matsuda <ronnie@dio.jp> | 2019-08-01 16:41:26 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2019-08-01 17:58:00 +0900 |
commit | af2129b4c74732c88ffce76e5c55c805cb9431f6 (patch) | |
tree | c74d8c85f81ea6b3a5e4209be247c9d83666bd4d /activerecord/lib | |
parent | dbf3e4882f9da95e34ed9086f182cf424aaac224 (diff) | |
download | rails-af2129b4c74732c88ffce76e5c55c805cb9431f6.tar.gz rails-af2129b4c74732c88ffce76e5c55c805cb9431f6.tar.bz2 rails-af2129b4c74732c88ffce76e5c55c805cb9431f6.zip |
Use `try` only when we're unsure if the receiver would respond_to the method
Diffstat (limited to 'activerecord/lib')
5 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 3346725f2d..e3886f394a 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -44,7 +44,7 @@ module ActiveRecord def decrement_counters_before_last_save if reflection.polymorphic? - model_was = owner.attribute_before_last_save(reflection.foreign_type).try(:constantize) + model_was = owner.attribute_before_last_save(reflection.foreign_type)&.constantize else model_was = klass end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb b/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb index 8df91c988b..75213e964b 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb @@ -24,7 +24,7 @@ WARNING: Rails was not able to disable referential integrity. This is most likely caused due to missing permissions. Rails needs superuser privileges to disable referential integrity. - cause: #{original_exception.try(:message)} + cause: #{original_exception&.message} WARNING raise e diff --git a/activerecord/lib/active_record/database_configurations.rb b/activerecord/lib/active_record/database_configurations.rb index fcf13a910c..c56a099769 100644 --- a/activerecord/lib/active_record/database_configurations.rb +++ b/activerecord/lib/active_record/database_configurations.rb @@ -152,7 +152,7 @@ module ActiveRecord def build_db_config_from_string(env_name, spec_name, config) url = config uri = URI.parse(url) - if uri.try(:scheme) + if uri&.scheme ActiveRecord::DatabaseConfigurations::UrlConfig.new(env_name, spec_name, url) end rescue URI::InvalidURIError diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index 509f21c9a5..0f110b4536 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -106,7 +106,7 @@ module ActiveRecord # Wraps the underlying database error as +cause+. class StatementInvalid < ActiveRecordError def initialize(message = nil, sql: nil, binds: nil) - super(message || $!.try(:message)) + super(message || $!&.message) @sql = sql @binds = binds end diff --git a/activerecord/lib/active_record/serialization.rb b/activerecord/lib/active_record/serialization.rb index 741fea43ce..9fc62a99f8 100644 --- a/activerecord/lib/active_record/serialization.rb +++ b/activerecord/lib/active_record/serialization.rb @@ -11,7 +11,7 @@ module ActiveRecord #:nodoc: end def serializable_hash(options = nil) - options = options.try(:dup) || {} + options = options ? options.dup : {} options[:except] = Array(options[:except]).map(&:to_s) options[:except] |= Array(self.class.inheritance_column) |