Feature #9405

Implicitly convert blocks to procs / remove blocks completely?

Added by alexeymuranov (Alexey Muranov) about 6 years ago. Updated about 6 years ago.

Target version:


While i am think of this, here is one more proposal.

If a block appears in a place where no block can appear, convert it automatically to a proc. For example:

p = do |n; s| s = gets; n.times do puts s end end
t = {|| }

When a block takes no arguments and is written with curly braces, to distinguish it easily from a hash (or from a set, who knows? #5478 :)), it would need to open with {||.

Maybe ultimately blocks can be completely replaced by procs and lambdas from user's perspective and only existe for the compiler. Unfortunately, for compatibility, this would require treating specially literal procs in method calls (differently from procs and lambdas passed as variable or expression values. The semantics of

foo(1) { |n| ... }

can be the following: the literal proc is converted to a block (which user never "sees") because it appears in a method call where no more arguments can appear.


Updated by nobu (Nobuyoshi Nakada) about 6 years ago

  • Status changed from Open to Rejected

It's the idea once implemented and abandoned.

Also available in: Atom PDF