Open vk0xOrg opened 4 years ago
I have thie error in Rails 5.0.7 and ruby 2.7.1
gems/faraday-0.12.2/lib/faraday/options.rb:166: warning: Capturing the given block using Proc.new is deprecated; use
&blockinstead
I don't know Ruby much but I tried to search a fix for this myself and tried to update the faraday package to a new version where it's fixed but I ran into dependency version mismatch problems.
Then I managed to hack fix it myself by following example in this blog explaining the change in the language https://medium.com/@amliving/proc-new-trick-c1df16185599.
It has similar looking syntax to what I have that gives a warning:
def random_method_three
prok = Proc.new
prok.call
end
That gets converted to this with the new syntax:
def uses_ampersand(trigger, &block)
if trigger && block_given?
block.call
end
end
https://blog.saeloun.com/2019/09/02/ruby-2-7-proc-without-block-warning.html also tries to explain theory begind this but examples were a bit more abstract.
Now in vi /var/lib/gems/2.7.0/gems/faraday-0.11.0/lib/faraday/options.rb
the apparent fix was to introduce &block
as a function argument instead of calling Proc.new
as the warning stated.
Changing the lines 159 and 160:
def self.memoized(key)
memoized_attributes[key.to_sym] = Proc.new
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{key}() self[:#{key}]; end
RUBY
end
To:
def self.memoized(key, &block)
memoized_attributes[key.to_sym] = block
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{key}() self[:#{key}]; end
RUBY
end
t
works now without warnings so I'll leave that there and maybe learn something new later if things break cause of it while hoping the package index would be getting the fix before that.
Running this on Ubuntu 20.04 with stock ruby installation following the normal installation guidance, nothing fancy there.
Well, that didn't work out too far. Getting this same warning from other code locations too:
$ t followers <handle>
/var/lib/gems/2.7.0/gems/faraday-0.11.0/lib/faraday/rack_builder.rb:55: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/var/lib/gems/2.7.0/gems/faraday-0.11.0/lib/faraday/options.rb:69: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
/var/lib/gems/2.7.0/gems/twitter-6.1.0/lib/twitter/utils.rb:25: warning: Capturing the given block using Proc.new is deprecated; use `&block` instead
Alright, this environment variable suppresses script warnings:
export RUBYOPT=-W0
Just drop that into .bashrc
while the official fix is on it's way and better remember to take it out if you're debugging something
Just noting that I'm getting this same issue with homebrew installed ruby (2.7.0) on Mac (10.13.6) in addition to this other bug in the installation progress https://github.com/sferik/t/issues/402.
I'm getting such a warning
.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/faraday-0.11.0/lib/faraday/options.rb:160: warning: Capturing the given block using Proc.new is deprecated; use
&blockinstead
Herewas mentioned that the warning was corrected in the following releases (>1.0).
t version
is3.1.0
gem info faraday
0.11.0
ruby --version
2.7.1
How to get rid of this warning?