From 838ce3aee47456573675ba2353f1573158caab32 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Mon, 10 Feb 2020 05:03:45 +0530 Subject: [PATCH] Cleanups since master is 2.2+ - Use safe navigation operator - Cleanup old "unused variable" comments and hack, this doesn't seem to warn on 2.3 onwards --- lib/rack/auth/abstract/request.rb | 2 +- lib/rack/show_exceptions.rb | 8 ++------ lib/rack/show_status.rb | 8 ++------ lib/rack/utils.rb | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/rack/auth/abstract/request.rb b/lib/rack/auth/abstract/request.rb index 34042c401..7b499f1b2 100644 --- a/lib/rack/auth/abstract/request.rb +++ b/lib/rack/auth/abstract/request.rb @@ -25,7 +25,7 @@ def parts end def scheme - @scheme ||= parts.first && parts.first.downcase + @scheme ||= parts.first&.downcase end def params diff --git a/lib/rack/show_exceptions.rb b/lib/rack/show_exceptions.rb index f5cc76c30..ad534b316 100644 --- a/lib/rack/show_exceptions.rb +++ b/lib/rack/show_exceptions.rb @@ -63,13 +63,9 @@ def dump_exception(exception) def pretty(env, exception) req = Rack::Request.new(env) - # This double assignment is to prevent an "unused variable" warning on - # Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me. - path = path = (req.script_name + req.path_info).squeeze("/") + path = (req.script_name + req.path_info).squeeze("/") - # This double assignment is to prevent an "unused variable" warning on - # Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me. - frames = frames = exception.backtrace.map { |line| + frames = exception.backtrace.map { |line| frame = OpenStruct.new if line =~ /(.*?):(\d+)(:in `(.*)')?/ frame.filename = $1 diff --git a/lib/rack/show_status.rb b/lib/rack/show_status.rb index 4d01d4486..2f511b925 100644 --- a/lib/rack/show_status.rb +++ b/lib/rack/show_status.rb @@ -23,15 +23,11 @@ def call(env) # client or server error, or explicit message if (status.to_i >= 400 && empty) || env[RACK_SHOWSTATUS_DETAIL] - # This double assignment is to prevent an "unused variable" warning on - # Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me. - req = req = Rack::Request.new(env) + req = Rack::Request.new(env) message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s - # This double assignment is to prevent an "unused variable" warning on - # Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me. - detail = detail = env[RACK_SHOWSTATUS_DETAIL] || message + detail = env[RACK_SHOWSTATUS_DETAIL] || message body = @template.result(binding) size = body.bytesize diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index f033c900d..a0d0354c5 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -152,7 +152,7 @@ def best_q_match(q_value_header, available_mimes) end.compact.sort_by do |match, quality| (match.split('/', 2).count('*') * -10) + quality end.last - matches && matches.first + matches&.first end ESCAPE_HTML = {