From af2129b4c74732c88ffce76e5c55c805cb9431f6 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 1 Aug 2019 16:41:26 +0900 Subject: Use `try` only when we're unsure if the receiver would respond_to the method --- actionpack/lib/action_controller/metal/conditional_get.rb | 2 +- actionpack/lib/action_controller/metal/content_security_policy.rb | 2 +- actionpack/lib/action_dispatch/http/feature_policy.rb | 2 +- actionpack/lib/action_dispatch/system_testing/browser.rb | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb index 29d1919ec5..f21e51a68a 100644 --- a/actionpack/lib/action_controller/metal/conditional_get.rb +++ b/actionpack/lib/action_controller/metal/conditional_get.rb @@ -17,7 +17,7 @@ module ActionController # of cached pages. # # class InvoicesController < ApplicationController - # etag { current_user.try :id } + # etag { current_user&.id } # # def show # # Etag will differ even for the same invoice when it's viewed by a different current_user diff --git a/actionpack/lib/action_controller/metal/content_security_policy.rb b/actionpack/lib/action_controller/metal/content_security_policy.rb index ebd90f07c8..25fc110bfe 100644 --- a/actionpack/lib/action_controller/metal/content_security_policy.rb +++ b/actionpack/lib/action_controller/metal/content_security_policy.rb @@ -45,7 +45,7 @@ module ActionController #:nodoc: end def current_content_security_policy - request.content_security_policy.try(:clone) || ActionDispatch::ContentSecurityPolicy.new + request.content_security_policy&.clone || ActionDispatch::ContentSecurityPolicy.new end end end diff --git a/actionpack/lib/action_dispatch/http/feature_policy.rb b/actionpack/lib/action_dispatch/http/feature_policy.rb index 78e982918d..c09690f9fc 100644 --- a/actionpack/lib/action_dispatch/http/feature_policy.rb +++ b/actionpack/lib/action_dispatch/http/feature_policy.rb @@ -42,7 +42,7 @@ module ActionDispatch #:nodoc: end def policy_empty?(policy) - policy.try(:directives) && policy.directives.empty? + policy&.directives&.empty? end end diff --git a/actionpack/lib/action_dispatch/system_testing/browser.rb b/actionpack/lib/action_dispatch/system_testing/browser.rb index e861e52f09..91f332be13 100644 --- a/actionpack/lib/action_dispatch/system_testing/browser.rb +++ b/actionpack/lib/action_dispatch/system_testing/browser.rb @@ -47,14 +47,14 @@ module ActionDispatch case type when :chrome if ::Selenium::WebDriver::Service.respond_to? :driver_path= - ::Selenium::WebDriver::Chrome::Service.driver_path.try(:call) + ::Selenium::WebDriver::Chrome::Service.driver_path&.call else # Selenium <= v3.141.0 ::Selenium::WebDriver::Chrome.driver_path end when :firefox if ::Selenium::WebDriver::Service.respond_to? :driver_path= - ::Selenium::WebDriver::Firefox::Service.driver_path.try(:call) + ::Selenium::WebDriver::Firefox::Service.driver_path&.call else # Selenium <= v3.141.0 ::Selenium::WebDriver::Firefox.driver_path -- cgit v1.2.3