Issue #5007 has been updated by trans (Thomas Sawyer).


=begin
I don't see how this solves the case presented in #6298.

Given:

  class BlockCollection
    def initialize(*procs)
      @procs = procs
    end
    def to_proc
      procs = @procs
      Proc.new{ |*a| procs.each{ |p| p.call_under(self, *a) } }
    end
  end

What is `self` here, or what should it be? Such that:

  module M
    A = Proc.new{ self }
  end

  bc = BlockCollection.new(A)

  bc.call  #=> M

  'F'.instance_eval(&bc)  #=> 'F'

=end

----------------------------------------
Feature #5007: Proc#call_under: Unifying instance_eval and instance_exec
https://bugs.ruby-lang.org/issues/5007#change-25944

Author: judofyr (Magnus Holm)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: 
Target version: 


I'm proposing a method called Proc#call_under (the name could be
discussed) which both unifies instance_eval and instance_exec, and makes
it possible to call a Proc with a block and a scope:

  Proc#call_under(self, *args, &blk):

    proc { self }.call_under(1) # => 1

    proc { |a| self + a }.call_under(1, 2) # => 3

    proc { |&b| self + b.call }.call_under(2) { 2 } # => 4


-- 
http://bugs.ruby-lang.org/