From: merch-redmine@... Date: 2019-07-11T02:33:39+00:00 Subject: [ruby-core:93657] [Ruby master Bug#10006] instance_exec uses incorrect binding with curried proc Issue #10006 has been updated by jeremyevans0 (Jeremy Evans). I think the current behavior is the behavior that should be expected. It mirrors the behavior you would expect if you implemented `Proc#curry` in Ruby: ```ruby class Test def test_func 140 end end # => :test_func p = ->(x, y) { x + y + test_func } curried = ->(y) { p.call(1, y) } test.instance_exec(2, &curried) ``` Changing `Proc#curry` to internally use `instance_exec` for curried procs would fix this case and break the opposite case: ```ruby class Test def test_func 140 end def p ->(x, y) { x + y + test_func } end end # Current behavior: works curried = Test.new.p.curry[1] # Proposed behavior using instance_exec: breaks #curried = ->(y) { instance_exec(1, y, &Test.new.p) } instance_exec(2, &curried) ``` That being said, there is a valid argument that `instance_exec(arg, &proc)` and `instance_exec(&proc.curry[arg])` should operate the same way, just as `proc.call(arg)` and `proc.curry[arg].call` operate the same way. ---------------------------------------- Bug #10006: instance_exec uses incorrect binding with curried proc https://bugs.ruby-lang.org/issues/10006#change-79267 * Author: ledbettj (John Ledbetter) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.2.0dev (2014-07-02 trunk 46660) [x86_64-darwin13] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN ---------------------------------------- After using `Proc#curry`, `instanve_eval`/`instance_exec` does not seem to work: ~~~ruby class Test def test_func 140 end end # => :test_func p = ->(x, y) { x + y + test_func } # => # test = Test.new # => # test.instance_exec(1, 2, &p) # => 143 curried = p.curry[1] # => # test.instance_exec(2, &curried) ~~~ ~~~ NameError: undefined local variable or method `test_func' for main:Object from (irb):6:in `block in irb_binding' from (irb):10:in `instance_exec' from (irb):10 from ./bin/irb:11:in `
' ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: