Project

General

Profile

Feature #10499

Eliminate implicit magic in Proc.new and Kernel#proc

Added by headius (Charles Nutter) over 4 years ago. Updated over 4 years ago.

Status:
Open
Priority:
Normal
Target version:
[ruby-core:66225]

Description

Proc.new and Kernel#proc have a little known feature: if called without a block, they capture whatever block was passed to the current method.

I propose that this feature should be removed, finally, since it:

  • Doesn't enhance readability (where is this block coming from?)
  • Doesn't reflect any other behavior in Ruby
  • Can lead to bugs (call either without a block accidentally and you aren't sure what you'll get)

I believe this was an implementation artifact in MRI, since the most recently-pushed block would still be on global stacks, which is where the logic for proc and Proc.new looked for it.

All argument syntaxes now support &block, which I believe is the correct way to clearly, explicitly capture the incoming block into an object.

Thoughts?


Related issues

Copied to Ruby trunk - Feature #15554: warn/error passing a block to a method which never use a blockOpenActions

Associated revisions

Revision 9f1fb0a1
Added by nobu (Nobuyoshi Nakada) 6 months ago

proc.c: proc without block

  • proc.c (proc_new): promoted lambda/proc/Proc.new with no block in a method called with a block to a warning/error.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

Updated by marcandre (Marc-Andre Lafortune) over 4 years ago

  • Category set to core
  • Assignee set to matz (Yukihiro Matsumoto)

I agree.

Deprecate first (2.2?), remove afterwards.

This would also simplify things if and when we want to warn/raise on unused blocks when calling user methods.

Updated by headius (Charles Nutter) over 4 years ago

Adding a deprecation warning would be easy if we can get buy-in from matz.

matz: ball's in your court, I think!

#3

Updated by k0kubun (Takashi Kokubun) 27 days ago

  • Copied to Feature #15554: warn/error passing a block to a method which never use a block added

Also available in: Atom PDF