Simplify multiple ifs into single case statement.

This commit is contained in:
Markus Reiter 2024-02-08 14:44:41 +01:00
parent 732e4438f4
commit dc21095731
No known key found for this signature in database
GPG Key ID: 245293B51702655B

View File

@ -90,10 +90,14 @@ module Cask
.returns(T.nilable(T.attached_class))
}
def self.try_new(ref, warn: false)
ref = Pathname(ref) if ref.is_a?(String)
return unless ref.is_a?(Pathname)
path = ref
path = case ref
when String
Pathname(ref)
when Pathname
ref
else
return
end
return if %w[.rb .json].exclude?(path.extname)
return unless path.expand_path.exist?