From 27d9c93f3ab622e17893320d02a36251e9b110d1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 15 Aug 2019 11:05:38 -0700 Subject: [PATCH] This fixes warnings on Ruby 2.7 Ruby 2.7 issues warnings for `Proc.new` without a block: ``` warning: Capturing the given block using Proc.new is deprecated; use `&block` instead ``` This patch converts the `Proc.new` calls in to `&block` --- lib/faraday/adapter/em_http.rb | 4 ++-- lib/faraday/options.rb | 2 +- lib/faraday/response.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/faraday/adapter/em_http.rb b/lib/faraday/adapter/em_http.rb index 626728b0c..897a8ef75 100644 --- a/lib/faraday/adapter/em_http.rb +++ b/lib/faraday/adapter/em_http.rb @@ -229,11 +229,11 @@ def running? @running end - def add + def add(&block) if running? perform_request { yield } else - @registered_procs << Proc.new + @registered_procs << block end @num_registered += 1 end diff --git a/lib/faraday/options.rb b/lib/faraday/options.rb index 1a2140fea..b5af43d1b 100644 --- a/lib/faraday/options.rb +++ b/lib/faraday/options.rb @@ -79,7 +79,7 @@ def fetch(key, *args) if !args.empty? send(key_setter, args.first) elsif block_given? - send(key_setter, Proc.new.call(key)) + send(key_setter, yield(key)) else raise self.class.fetch_error_class, "key not found: #{key.inspect}" end diff --git a/lib/faraday/response.rb b/lib/faraday/response.rb index 09d4b228e..0da52f112 100644 --- a/lib/faraday/response.rb +++ b/lib/faraday/response.rb @@ -55,9 +55,9 @@ def finished? !!env end - def on_complete + def on_complete(&block) if !finished? - @on_complete_callbacks << Proc.new + @on_complete_callbacks << block else yield(env) end