From: ko1@... Date: 2019-01-16T10:12:46+00:00 Subject: [ruby-core:91121] [Ruby trunk Bug#15539] Proc.new with no block shouldn't always warn Issue #15539 has been updated by ko1 (Koichi Sasada). Status changed from Open to Rejected > makes it no longer possible to have a default value for a positional argument that uses the block Surprisingly, we can: ``` def foo o = binding.local_variable_get(:b), &b p o.class end foo{} #=> Proc ``` (of course it is joke code. it is too implementation dependent code so we shouldn't rely on this behavior) Anyway, I close this ticket and discuss more on new ticket I'll file. Thanks, Koichi ---------------------------------------- Bug #15539: Proc.new with no block shouldn't always warn https://bugs.ruby-lang.org/issues/15539#change-76353 * Author: tenderlovemaking (Aaron Patterson) * Status: Rejected * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- Hi, r66772 introduced a warning for the following code: ``` ruby def foo bar = Proc.new bar.call end foo { p "block" } # warn foo ->() { p "block" } # no warn ``` I don't think this case of `Proc.new` should warn. To eliminate warnings, I have to rewrite as: ``` ruby def foo bar = nil if bar bar.call else yield end end ``` Rails uses this "Proc.new" trick here: * https://github.com/rails/rails/blob/a08827a90b5a9be79379019cf5b242bd7236d2e3/actionpack/lib/action_controller/metal.rb#L29 * https://github.com/rails/rails/blob/a08827a90b5a9be79379019cf5b242bd7236d2e3/actionpack/lib/action_dispatch/middleware/stack.rb#L100 * https://github.com/rails/rails/blob/a08827a90b5a9be79379019cf5b242bd7236d2e3/activerecord/lib/active_record/statement_cache.rb#L116 * https://github.com/rails/rails/blob/a08827a90b5a9be79379019cf5b242bd7236d2e3/activesupport/lib/active_support/notifications/fanout.rb#L21 I can change Rails, but I want to know why and I don't see any discussion of r66772 (the commit doesn't have a feature number). Thanks! -- https://bugs.ruby-lang.org/ Unsubscribe: